@dbml/parse 7.0.0-alpha.0 → 7.0.0-alpha.1

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 (26) hide show
  1. package/dist/__tests__/examples/wildcard/wildcard.test.d.ts +1 -0
  2. package/dist/dbml-parse.js +17 -15
  3. package/dist/dbml-parse.mjs +355 -313
  4. package/dist/src/compiler/index.d.ts +7 -2
  5. package/dist/src/compiler/queries/transform/applyTextEdits.d.ts +1 -1
  6. package/dist/src/compiler/queries/transform/index.d.ts +1 -0
  7. package/dist/src/compiler/queries/transform/syncDiagramView.d.ts +11 -2
  8. package/dist/src/core/analyzer/validator/elementValidators/checks.d.ts +5 -2
  9. package/dist/src/core/analyzer/validator/elementValidators/custom.d.ts +5 -2
  10. package/dist/src/core/analyzer/validator/elementValidators/diagramView.d.ts +9 -3
  11. package/dist/src/core/analyzer/validator/elementValidators/enum.d.ts +5 -2
  12. package/dist/src/core/analyzer/validator/elementValidators/indexes.d.ts +5 -2
  13. package/dist/src/core/analyzer/validator/elementValidators/note.d.ts +5 -2
  14. package/dist/src/core/analyzer/validator/elementValidators/project.d.ts +5 -2
  15. package/dist/src/core/analyzer/validator/elementValidators/records.d.ts +5 -2
  16. package/dist/src/core/analyzer/validator/elementValidators/ref.d.ts +5 -2
  17. package/dist/src/core/analyzer/validator/elementValidators/table.d.ts +5 -2
  18. package/dist/src/core/analyzer/validator/elementValidators/tableGroup.d.ts +5 -2
  19. package/dist/src/core/analyzer/validator/elementValidators/tablePartial.d.ts +5 -2
  20. package/dist/src/core/analyzer/validator/types.d.ts +5 -2
  21. package/dist/src/core/interpreter/types.d.ts +3 -5
  22. package/dist/src/core/lexer/tokens.d.ts +2 -1
  23. package/dist/src/core/parser/nodes.d.ts +7 -0
  24. package/dist/src/core/parser/utils.d.ts +1 -0
  25. package/dist/src/index.d.ts +2 -2
  26. package/package.json +2 -2
@@ -3,10 +3,10 @@ import { SyntaxToken } from '../core/lexer/tokens';
3
3
  import { Database } from '../core/interpreter/types';
4
4
  import { default as Report } from '../core/report';
5
5
  import { DBMLCompletionItemProvider, DBMLDefinitionProvider, DBMLReferencesProvider, DBMLDiagnosticsProvider } from '../services/index';
6
- import { TextEdit, TableNameInput } from './queries/transform';
6
+ import { TextEdit, TableNameInput, DiagramViewSyncOperation, DiagramViewBlock } from './queries/transform';
7
7
  import { splitQualifiedIdentifier, unescapeString, escapeString, formatRecordValue, isValidIdentifier, addDoubleQuoteIfNeeded } from './queries/utils';
8
8
  export { ScopeKind } from './types';
9
- export type { TextEdit, TableNameInput };
9
+ export type { TextEdit, TableNameInput, DiagramViewSyncOperation, DiagramViewBlock };
10
10
  export { splitQualifiedIdentifier, unescapeString, escapeString, formatRecordValue, isValidIdentifier, addDoubleQuoteIfNeeded };
11
11
  export default class Compiler {
12
12
  private source;
@@ -17,6 +17,11 @@ export default class Compiler {
17
17
  private query;
18
18
  private interpret;
19
19
  renameTable(oldName: TableNameInput, newName: TableNameInput): string;
20
+ syncDiagramView(operations: DiagramViewSyncOperation[], blocks?: DiagramViewBlock[]): {
21
+ newDbml: string;
22
+ edits: TextEdit[];
23
+ };
24
+ findDiagramViewBlocks(): DiagramViewBlock[];
20
25
  applyTextEdits(edits: TextEdit[]): string;
21
26
  readonly token: {
22
27
  invalidStream: () => readonly SyntaxToken[];
@@ -10,4 +10,4 @@ export interface TextEdit {
10
10
  * @param edits - Array of text edits to apply
11
11
  * @returns The modified source string with all edits applied
12
12
  */
13
- export declare function applyTextEdits(source: string, edits: TextEdit[]): string;
13
+ export declare function applyTextEdits(source: string, edits: TextEdit[], sorted?: boolean): string;
@@ -1,3 +1,4 @@
1
1
  export { renameTable } from './renameTable';
2
2
  export { applyTextEdits, type TextEdit } from './applyTextEdits';
3
3
  export { type TableNameInput } from './utils';
4
+ export { syncDiagramView, findDiagramViewBlocks, type DiagramViewSyncOperation, type DiagramViewBlock } from './syncDiagramView';
@@ -1,3 +1,4 @@
1
+ import { TextEdit } from './applyTextEdits';
1
2
  export interface DiagramViewSyncOperation {
2
3
  operation: 'create' | 'update' | 'delete';
3
4
  name: string;
@@ -18,13 +19,21 @@ export interface DiagramViewSyncOperation {
18
19
  }> | null;
19
20
  };
20
21
  }
22
+ export interface DiagramViewBlock {
23
+ name: string;
24
+ startIndex: number;
25
+ endIndex: number;
26
+ }
27
+ export declare function findDiagramViewBlocks(source: string): DiagramViewBlock[];
21
28
  /**
22
29
  * Synchronizes DiagramView blocks in DBML source code.
23
30
  *
24
31
  * @param dbml - The original DBML source code
25
32
  * @param operations - Array of operations to apply (create, update, delete)
26
- * @returns Object containing the new DBML source code
33
+ * @param blocks - Optional pre-parsed blocks from findDiagramViewBlocks. If not provided, parses internally.
34
+ * @returns Object containing the new DBML source code and the text edits applied
27
35
  */
28
- export declare function syncDiagramView(dbml: string, operations: DiagramViewSyncOperation[]): {
36
+ export declare function syncDiagramView(dbml: string, operations: DiagramViewSyncOperation[], blocks?: DiagramViewBlock[]): {
29
37
  newDbml: string;
38
+ edits: TextEdit[];
30
39
  };
@@ -1,5 +1,5 @@
1
1
  import { default as SymbolFactory } from '../../symbol/factory';
2
- import { CompileError } from '../../../errors';
2
+ import { CompileError, CompileWarning } from '../../../errors';
3
3
  import { ElementDeclarationNode } from '../../../parser/nodes';
4
4
  import { SyntaxToken } from '../../../lexer/tokens';
5
5
  import { ElementValidator } from '../types';
@@ -11,7 +11,10 @@ export default class ChecksValidator implements ElementValidator {
11
11
  constructor(declarationNode: ElementDeclarationNode & {
12
12
  type: SyntaxToken;
13
13
  }, publicSymbolTable: SymbolTable, symbolFactory: SymbolFactory);
14
- validate(): CompileError[];
14
+ validate(): {
15
+ errors: CompileError[];
16
+ warnings: CompileWarning[];
17
+ };
15
18
  private validateContext;
16
19
  private validateName;
17
20
  private validateAlias;
@@ -1,4 +1,4 @@
1
- import { CompileError } from '../../../errors';
1
+ import { CompileError, CompileWarning } from '../../../errors';
2
2
  import { BlockExpressionNode, ElementDeclarationNode, FunctionApplicationNode } from '../../../parser/nodes';
3
3
  import { default as SymbolFactory } from '../../symbol/factory';
4
4
  import { SyntaxToken } from '../../../lexer/tokens';
@@ -11,7 +11,10 @@ export default class CustomValidator implements ElementValidator {
11
11
  constructor(declarationNode: ElementDeclarationNode & {
12
12
  type: SyntaxToken;
13
13
  }, publicSymbolTable: SymbolTable, symbolFactory: SymbolFactory);
14
- validate(): CompileError[];
14
+ validate(): {
15
+ errors: CompileError[];
16
+ warnings: CompileWarning[];
17
+ };
15
18
  private validateContext;
16
19
  private validateName;
17
20
  private validateAlias;
@@ -11,14 +11,20 @@ export default class DiagramViewValidator implements ElementValidator {
11
11
  constructor(declarationNode: ElementDeclarationNode & {
12
12
  type: SyntaxToken;
13
13
  }, publicSymbolTable: SymbolTable, symbolFactory: SymbolFactory);
14
- validate(): CompileError[];
14
+ validate(): {
15
+ errors: CompileError[];
16
+ warnings: CompileWarning[];
17
+ };
15
18
  private validateContext;
16
19
  private validateName;
17
20
  private validateAlias;
18
21
  registerElement(): CompileError[];
19
22
  private validateSettingList;
20
- validateBody(body?: FunctionApplicationNode | BlockExpressionNode): (CompileError | CompileWarning)[];
21
- validateFields(fields: FunctionApplicationNode[]): (CompileError | CompileWarning)[];
23
+ validateBody(body?: FunctionApplicationNode | BlockExpressionNode): {
24
+ errors: CompileError[];
25
+ warnings: CompileWarning[];
26
+ };
27
+ validateFields(fields: FunctionApplicationNode[]): CompileError[];
22
28
  private validateSubElements;
23
29
  private validateSubBlock;
24
30
  registerSubBlockFields(sub: ElementDeclarationNode): CompileError[];
@@ -1,5 +1,5 @@
1
1
  import { default as SymbolFactory } from '../../symbol/factory';
2
- import { CompileError } from '../../../errors';
2
+ import { CompileError, CompileWarning } from '../../../errors';
3
3
  import { BlockExpressionNode, ElementDeclarationNode, FunctionApplicationNode, ListExpressionNode } from '../../../parser/nodes';
4
4
  import { SyntaxToken } from '../../../lexer/tokens';
5
5
  import { ElementValidator } from '../types';
@@ -11,7 +11,10 @@ export default class EnumValidator implements ElementValidator {
11
11
  constructor(declarationNode: ElementDeclarationNode & {
12
12
  type: SyntaxToken;
13
13
  }, publicSymbolTable: SymbolTable, symbolFactory: SymbolFactory);
14
- validate(): CompileError[];
14
+ validate(): {
15
+ errors: CompileError[];
16
+ warnings: CompileWarning[];
17
+ };
15
18
  private validateContext;
16
19
  private validateName;
17
20
  private validateAlias;
@@ -1,5 +1,5 @@
1
1
  import { default as SymbolFactory } from '../../symbol/factory';
2
- import { CompileError } from '../../../errors';
2
+ import { CompileError, CompileWarning } from '../../../errors';
3
3
  import { ElementDeclarationNode, SyntaxNode } from '../../../parser/nodes';
4
4
  import { SyntaxToken } from '../../../lexer/tokens';
5
5
  import { ElementValidator } from '../types';
@@ -11,7 +11,10 @@ export default class IndexesValidator implements ElementValidator {
11
11
  constructor(declarationNode: ElementDeclarationNode & {
12
12
  type: SyntaxToken;
13
13
  }, publicSymbolTable: SymbolTable, symbolFactory: SymbolFactory);
14
- validate(): CompileError[];
14
+ validate(): {
15
+ errors: CompileError[];
16
+ warnings: CompileWarning[];
17
+ };
15
18
  private validateContext;
16
19
  private validateName;
17
20
  private validateAlias;
@@ -1,5 +1,5 @@
1
1
  import { default as SymbolFactory } from '../../symbol/factory';
2
- import { CompileError } from '../../../errors';
2
+ import { CompileError, CompileWarning } from '../../../errors';
3
3
  import { BlockExpressionNode, ElementDeclarationNode, FunctionApplicationNode } from '../../../parser/nodes';
4
4
  import { SyntaxToken } from '../../../lexer/tokens';
5
5
  import { ElementValidator } from '../types';
@@ -11,7 +11,10 @@ export default class NoteValidator implements ElementValidator {
11
11
  constructor(declarationNode: ElementDeclarationNode & {
12
12
  type: SyntaxToken;
13
13
  }, publicSymbolTable: SymbolTable, symbolFactory: SymbolFactory);
14
- validate(): CompileError[];
14
+ validate(): {
15
+ errors: CompileError[];
16
+ warnings: CompileWarning[];
17
+ };
15
18
  private validateContext;
16
19
  private validateName;
17
20
  private validateAlias;
@@ -1,5 +1,5 @@
1
1
  import { default as SymbolFactory } from '../../symbol/factory';
2
- import { CompileError } from '../../../errors';
2
+ import { CompileError, CompileWarning } from '../../../errors';
3
3
  import { BlockExpressionNode, ElementDeclarationNode, FunctionApplicationNode } from '../../../parser/nodes';
4
4
  import { SyntaxToken } from '../../../lexer/tokens';
5
5
  import { ElementValidator } from '../types';
@@ -11,7 +11,10 @@ export default class ProjectValidator implements ElementValidator {
11
11
  constructor(declarationNode: ElementDeclarationNode & {
12
12
  type: SyntaxToken;
13
13
  }, publicSymbolTable: SymbolTable, symbolFactory: SymbolFactory);
14
- validate(): CompileError[];
14
+ validate(): {
15
+ errors: CompileError[];
16
+ warnings: CompileWarning[];
17
+ };
15
18
  private validateContext;
16
19
  private validateName;
17
20
  private validateAlias;
@@ -1,5 +1,5 @@
1
1
  import { default as SymbolFactory } from '../../symbol/factory';
2
- import { CompileError } from '../../../errors';
2
+ import { CompileError, CompileWarning } from '../../../errors';
3
3
  import { BlockExpressionNode, ElementDeclarationNode, FunctionApplicationNode } from '../../../parser/nodes';
4
4
  import { SyntaxToken } from '../../../lexer/tokens';
5
5
  import { ElementValidator } from '../types';
@@ -11,7 +11,10 @@ export default class RecordsValidator implements ElementValidator {
11
11
  constructor(declarationNode: ElementDeclarationNode & {
12
12
  type: SyntaxToken;
13
13
  }, publicSymbolTable: SymbolTable, symbolFactory: SymbolFactory);
14
- validate(): CompileError[];
14
+ validate(): {
15
+ errors: CompileError[];
16
+ warnings: CompileWarning[];
17
+ };
15
18
  private validateContext;
16
19
  private validateName;
17
20
  private validateTopLevelName;
@@ -1,6 +1,6 @@
1
1
  import { SyntaxToken } from '../../../lexer/tokens';
2
2
  import { default as SymbolFactory } from '../../symbol/factory';
3
- import { CompileError } from '../../../errors';
3
+ import { CompileError, CompileWarning } from '../../../errors';
4
4
  import { BlockExpressionNode, ElementDeclarationNode, FunctionApplicationNode, ListExpressionNode } from '../../../parser/nodes';
5
5
  import { ElementValidator } from '../types';
6
6
  import { default as SymbolTable } from '../../symbol/symbolTable';
@@ -11,7 +11,10 @@ export default class RefValidator implements ElementValidator {
11
11
  constructor(declarationNode: ElementDeclarationNode & {
12
12
  type: SyntaxToken;
13
13
  }, publicSymbolTable: SymbolTable, symbolFactory: SymbolFactory);
14
- validate(): CompileError[];
14
+ validate(): {
15
+ errors: CompileError[];
16
+ warnings: CompileWarning[];
17
+ };
15
18
  private validateContext;
16
19
  private validateName;
17
20
  private validateAlias;
@@ -1,5 +1,5 @@
1
1
  import { default as SymbolFactory } from '../../symbol/factory';
2
- import { CompileError } from '../../../errors';
2
+ import { CompileError, CompileWarning } from '../../../errors';
3
3
  import { BlockExpressionNode, ElementDeclarationNode, ExpressionNode, FunctionApplicationNode } from '../../../parser/nodes';
4
4
  import { ElementValidator } from '../types';
5
5
  import { SyntaxToken } from '../../../lexer/tokens';
@@ -11,7 +11,10 @@ export default class TableValidator implements ElementValidator {
11
11
  constructor(declarationNode: ElementDeclarationNode & {
12
12
  type: SyntaxToken;
13
13
  }, publicSymbolTable: SymbolTable, symbolFactory: SymbolFactory);
14
- validate(): CompileError[];
14
+ validate(): {
15
+ errors: CompileError[];
16
+ warnings: CompileWarning[];
17
+ };
15
18
  private validateContext;
16
19
  private validateName;
17
20
  private validateAlias;
@@ -1,4 +1,4 @@
1
- import { CompileError } from '../../../errors';
1
+ import { CompileError, CompileWarning } from '../../../errors';
2
2
  import { ElementValidator } from '../types';
3
3
  import { default as SymbolTable } from '../../symbol/symbolTable';
4
4
  import { SyntaxToken } from '../../../lexer/tokens';
@@ -11,7 +11,10 @@ export default class TableGroupValidator implements ElementValidator {
11
11
  constructor(declarationNode: ElementDeclarationNode & {
12
12
  type: SyntaxToken;
13
13
  }, publicSymbolTable: SymbolTable, symbolFactory: SymbolFactory);
14
- validate(): CompileError[];
14
+ validate(): {
15
+ errors: CompileError[];
16
+ warnings: CompileWarning[];
17
+ };
15
18
  private validateContext;
16
19
  private validateName;
17
20
  private validateAlias;
@@ -1,5 +1,5 @@
1
1
  import { default as SymbolFactory } from '../../symbol/factory';
2
- import { CompileError } from '../../../errors';
2
+ import { CompileError, CompileWarning } from '../../../errors';
3
3
  import { BlockExpressionNode, ElementDeclarationNode, ExpressionNode, FunctionApplicationNode } from '../../../parser/nodes';
4
4
  import { ElementValidator } from '../types';
5
5
  import { SyntaxToken } from '../../../lexer/tokens';
@@ -11,7 +11,10 @@ export default class TablePartialValidator implements ElementValidator {
11
11
  constructor(declarationNode: ElementDeclarationNode & {
12
12
  type: SyntaxToken;
13
13
  }, publicSymbolTable: SymbolTable, symbolFactory: SymbolFactory);
14
- validate(): CompileError[];
14
+ validate(): {
15
+ errors: CompileError[];
16
+ warnings: CompileWarning[];
17
+ };
15
18
  private validateContext;
16
19
  private validateName;
17
20
  private validateAlias;
@@ -1,4 +1,7 @@
1
- import { CompileError } from '../../errors';
1
+ import { CompileError, CompileWarning } from '../../errors';
2
2
  export interface ElementValidator {
3
- validate(): CompileError[];
3
+ validate(): {
4
+ errors: CompileError[];
5
+ warnings: CompileWarning[];
6
+ };
4
7
  }
@@ -34,10 +34,6 @@ export interface DiagramView {
34
34
  schemaName: string | null;
35
35
  visibleEntities: FilterConfig;
36
36
  token: TokenPosition;
37
- /** Internal: tracks which dims used explicit wildcard (*). Stripped before output. */
38
- _explicitWildcards?: Set<string>;
39
- /** Internal: tracks which dims were explicitly declared in the DBML. Stripped before output. */
40
- _explicitlySet?: Set<string>;
41
37
  }
42
38
  export interface InterpreterDatabase {
43
39
  schema: [];
@@ -59,7 +55,9 @@ export interface InterpreterDatabase {
59
55
  recordsElements: ElementDeclarationNode[];
60
56
  cachedMergedTables: Map<Table, Table>;
61
57
  source: string;
62
- diagramViews?: Map<ElementDeclarationNode, DiagramView>;
58
+ diagramViews: Map<ElementDeclarationNode, DiagramView>;
59
+ diagramViewWildcards: Map<DiagramView, Set<string>>;
60
+ diagramViewExplicitlySet: Map<DiagramView, Set<string>>;
63
61
  }
64
62
  export type RecordValueType = 'string' | 'bool' | 'integer' | 'real' | 'date' | 'time' | 'datetime' | string;
65
63
  export interface RecordValue {
@@ -23,7 +23,8 @@ export declare enum SyntaxTokenKind {
23
23
  SEMICOLON = "<semicolon>",
24
24
  COLON = "<colon>",
25
25
  SINGLE_LINE_COMMENT = "<single-line-comment>",
26
- MULTILINE_COMMENT = "<multiline-comment>"
26
+ MULTILINE_COMMENT = "<multiline-comment>",
27
+ WILDCARD = "<wildcard>"
27
28
  }
28
29
  export declare function isTriviaToken(token: SyntaxToken): boolean;
29
30
  export declare function isOp(c?: string): boolean;
@@ -39,6 +39,7 @@ export declare enum SyntaxNodeKind {
39
39
  PRIMARY_EXPRESSION = "<primary-expression>",
40
40
  GROUP_EXPRESSION = "<group-expression>",
41
41
  COMMA_EXPRESSION = "<comma-expression>",
42
+ WILDCARD = "<wildcard>",
42
43
  EMPTY = "<dummy>",
43
44
  ARRAY = "<array>"
44
45
  }
@@ -192,6 +193,12 @@ export declare class LiteralNode extends SyntaxNode {
192
193
  literal?: SyntaxToken;
193
194
  }, id: SyntaxNodeId);
194
195
  }
196
+ export declare class WildcardNode extends SyntaxNode {
197
+ token?: SyntaxToken;
198
+ constructor({ token }: {
199
+ token?: SyntaxToken;
200
+ }, id: SyntaxNodeId);
201
+ }
195
202
  export declare class VariableNode extends SyntaxNode {
196
203
  variable?: SyntaxToken;
197
204
  constructor({ variable }: {
@@ -29,6 +29,7 @@ export declare function isExpressionAVariableNode(value?: unknown): value is Pri
29
29
  variable: SyntaxToken;
30
30
  };
31
31
  };
32
+ export declare function isWildcardExpression(node: SyntaxNode | undefined): boolean;
32
33
  export declare function isExpressionAnIdentifierNode(value?: unknown): value is PrimaryExpressionNode & {
33
34
  expression: VariableNode & {
34
35
  variable: {
@@ -8,7 +8,7 @@ export { CompileError, CompileErrorCode, } from './core/errors';
8
8
  export { type Position, } from './core/types';
9
9
  export { ScopeKind, splitQualifiedIdentifier, unescapeString, escapeString, formatRecordValue, isValidIdentifier, addDoubleQuoteIfNeeded, } from './compiler/index';
10
10
  export { type Database, type Table, type Column, type Enum, type Ref, type Project, type TableGroup, type TablePartial, type DiagramView, type FilterConfig, } from './core/interpreter/types';
11
- export { syncDiagramView } from './compiler/queries/transform/syncDiagramView';
12
- export type { DiagramViewSyncOperation } from './compiler/queries/transform/syncDiagramView';
11
+ export type { DiagramViewSyncOperation, DiagramViewBlock } from './compiler/queries/transform/syncDiagramView';
12
+ export type { TextEdit } from './compiler/queries/transform/applyTextEdits';
13
13
  export { dbmlMonarchTokensProvider } from './services/monarch';
14
14
  export { Compiler, services };
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": "7.0.0-alpha.0",
4
+ "version": "7.0.0-alpha.1",
5
5
  "description": "DBML parser v2",
6
6
  "author": "Holistics <dev@holistics.io>",
7
7
  "license": "Apache-2.0",
@@ -45,5 +45,5 @@
45
45
  "engines": {
46
46
  "node": ">=18"
47
47
  },
48
- "gitHead": "cb925c52bc255aa63688dc04db48f2ad5d7129c9"
48
+ "gitHead": "283f3bcf7373ecab1e808e8a8035ce906ee6a52e"
49
49
  }