@dbml/parse 11.0.0-alpha.2 → 11.0.0-alpha.4

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.
@@ -9,10 +9,6 @@ import { NodeSymbolIdGenerator, SymbolFactory } from '../core/types/symbol';
9
9
  import { DBMLCodeActionProvider, DBMLCompletionItemProvider, DBMLDefinitionProvider, DBMLDiagnosticsProvider, DBMLReferencesProvider } from '../services/index';
10
10
  import { DbmlProjectLayout } from './projectLayout';
11
11
  import { addDoubleQuoteIfNeeded, escapeString, formatRecordValue, isValidIdentifier, normalizeQualifiedName, splitQualifiedIdentifier, unescapeString } from './queries/utils';
12
- /**
13
- * Grammar switches a dialect asks for, gathered in one place so the Compiler does not grow a
14
- * parameter per stage. Every switch inside is off by default, so DBML is exactly what it was.
15
- */
16
12
  export interface DialectOptions {
17
13
  lexer?: LexerOptions;
18
14
  parser?: ParserOptions;
@@ -28,12 +24,6 @@ export default class Compiler {
28
24
  readonly explicitModules: GlobalModule[] | undefined;
29
25
  private readonly explicitDialect;
30
26
  readonly dialect: DialectOptions;
31
- /**
32
- * @param layout the structure of the DbmlProject
33
- * @param modules the element vocabulary for every file. When omitted, each file uses the
34
- * modules of its own kind (DBML or architecture).
35
- * @param dialect grammar switches for every file. When omitted, each file gets its kind's switches.
36
- */
37
27
  constructor(layout: DbmlProjectLayout, modules?: GlobalModule[], dialect?: DialectOptions);
38
28
  getSource(filepath: Filepath): string | undefined;
39
29
  lexerOptions(): LexerOptions;
@@ -1,13 +1,8 @@
1
1
  import { Filepath } from '../../../core/types/filepath';
2
2
  import { default as Compiler } from '../../index';
3
3
  /**
4
- * Renames an architecture element (node, group or note box) in `filepath`.
5
- *
6
- * With an `as` alias, links, groups and metadata name the element by its alias, so only the
7
- * name changes. Without one the name is the handle, so every link endpoint, group member and
4
+ * With an `as` alias only the name changes. Without one, every link endpoint, group member and
8
5
  * metadata target in the same file that names it is renamed too.
9
- *
10
- * Returns a map of absolute file paths to new source content. An empty map indicates a no-op
11
- * (lookup miss or name collision).
6
+ * An empty map means no change (lookup miss or name collision).
12
7
  */
13
8
  export declare function renameElement(this: Compiler, filepath: Filepath, oldHandle: string, newName: string): Map<string, string>;
@@ -1,6 +1,17 @@
1
1
  import { Filepath } from '../../../../core/types/filepath';
2
- import { ElementDeclarationNode } from '../../../../core/types/nodes';
2
+ import { AttributeNode, ElementDeclarationNode, ListExpressionNode } from '../../../../core/types/nodes';
3
3
  import { default as Compiler } from '../../../index';
4
+ import { TextEdit } from '../applyTextEdits';
4
5
  export declare function archDeclarations(compiler: Compiler, filepath: Filepath): ElementDeclarationNode[];
5
6
  export declare function findArchElement(compiler: Compiler, filepath: Filepath, handle: string): ElementDeclarationNode | undefined;
6
- export declare function findArchLink(compiler: Compiler, filepath: Filepath, from: string, to: string): ElementDeclarationNode | undefined;
7
+ export type ArchLinkDefinition = {
8
+ kind: 'standalone';
9
+ declaration: ElementDeclarationNode;
10
+ } | {
11
+ kind: 'inline';
12
+ element: ElementDeclarationNode;
13
+ attribute: AttributeNode;
14
+ op: string;
15
+ };
16
+ export declare function findArchLink(compiler: Compiler, filepath: Filepath, from: string, to: string): ArchLinkDefinition | undefined;
17
+ export declare function removeAttributeEdit(list: ListExpressionNode, attribute: AttributeNode, source: string): TextEdit;
@@ -1,5 +1,4 @@
1
1
  export declare const ICON_NAMES: string[];
2
- /** what people actually type; an alias costs one line and saves a diagnostic */
3
2
  export declare const ICON_ALIAS: Record<string, string>;
4
3
  export declare const resolveIcon: (name: string) => string;
5
4
  export declare const isIconName: (name: string) => boolean;
@@ -1,14 +1,16 @@
1
- import { ElementDeclarationNode, ListExpressionNode, SyntaxNode } from '../types/nodes';
1
+ import { AttributeNode, ElementDeclarationNode, ListExpressionNode, SyntaxNode } from '../types/nodes';
2
2
  import { ArchSettingValue, ArchSettings } from '../types/schemaJson';
3
- export type ArchSort = 'node' | 'group' | 'note' | 'kind' | 'link' | 'metadata' | 'project';
3
+ export type ArchSort = 'node' | 'group' | 'kind' | 'link' | 'metadata' | 'project';
4
4
  export declare const declarationWord: (node: ElementDeclarationNode) => string | undefined;
5
5
  export declare function isTopLevel(node: SyntaxNode): node is ElementDeclarationNode;
6
6
  export declare function archSort(node: SyntaxNode): ArchSort | undefined;
7
+ export declare const isTopLevelNote: (node: SyntaxNode) => boolean;
7
8
  export declare function topLevelDeclaration(node: SyntaxNode): ElementDeclarationNode | undefined;
8
9
  export declare function nameOf(node?: SyntaxNode): string | undefined;
9
10
  export declare const handleOf: (node: ElementDeclarationNode) => string | undefined;
10
11
  export declare function numberOf(node?: SyntaxNode): number | null;
11
12
  export declare function valueOf(node: SyntaxNode): ArchSettingValue | undefined;
13
+ export declare const isInlineLinkKey: (key: string) => boolean;
12
14
  export declare function settingsOf(list?: ListExpressionNode): ArchSettings;
13
15
  export declare function bodyOf(node: ElementDeclarationNode): SyntaxNode[];
14
16
  export interface Row {
@@ -30,6 +32,13 @@ export interface LinkParts {
30
32
  infix: Infix;
31
33
  }
32
34
  export declare function linkPartsOf(declaration: ElementDeclarationNode): LinkParts | undefined;
35
+ export declare function isInlineLink(attribute: AttributeNode): boolean;
36
+ export declare function inlineLinksOf(declaration: ElementDeclarationNode): AttributeNode[];
37
+ export interface InlineLink {
38
+ op: string;
39
+ target: SyntaxNode;
40
+ }
41
+ export declare function inlineLinkOf(attribute: AttributeNode): InlineLink | undefined;
33
42
  export interface Property {
34
43
  key: string;
35
44
  value: ArchSettingValue | undefined;
@@ -37,7 +46,6 @@ export interface Property {
37
46
  export declare function propertyOf(node: SyntaxNode): Property | undefined;
38
47
  export declare function noteDeclarationOf(declaration: ElementDeclarationNode): ElementDeclarationNode | undefined;
39
48
  export declare function noteTextOf(note: ElementDeclarationNode): string;
40
- export declare function noteBoxTextOf(declaration: ElementDeclarationNode): string;
41
49
  export declare const IMAGE_URL: RegExp;
42
50
  export declare const IMAGE_REFUSED = "A picture must be an https: URL or a data:image/ URI.";
43
51
  export interface BodyRead {
@@ -1,11 +1,11 @@
1
1
  import { default as Compiler } from '../../../compiler';
2
2
  import { Filepath } from '../../types/filepath';
3
3
  import { default as Report } from '../../types/report';
4
- import { ArchSettings, Group, Kind, Link, Node, NoteBox } from '../../types/schemaJson';
4
+ import { ArchSettings, Group, Kind, Link, Node } from '../../types/schemaJson';
5
5
  import { ElementSymbol, KindSymbol } from '../../types/symbol';
6
6
  import { ArchMetadataElementMetadata, LinkMetadata } from '../../types/symbol/metadata';
7
- export declare function interpretElement(compiler: Compiler, symbol: ElementSymbol, filepath: Filepath): Report<Node | Group | NoteBox | undefined>;
7
+ export declare function interpretElement(compiler: Compiler, symbol: ElementSymbol, filepath: Filepath): Report<Node | Group | undefined>;
8
8
  export declare function interpretKind(symbol: KindSymbol): Report<Kind | undefined>;
9
9
  export declare function builtinKinds(): Kind[];
10
- export declare function interpretLink(compiler: Compiler, metadata: LinkMetadata): Report<Link | undefined>;
10
+ export declare function interpretLink(compiler: Compiler, metadata: LinkMetadata, filepath: Filepath): Report<Link | undefined>;
11
11
  export declare function interpretArchMetadata(metadata: ArchMetadataElementMetadata): Report<ArchSettings>;
@@ -4,4 +4,4 @@ import { NodeSymbol, SymbolKind } from '../../types/symbol';
4
4
  export declare function lookupVisible(compiler: Compiler, filepath: Filepath, kind: SymbolKind, name: string): NodeSymbol | undefined;
5
5
  export declare function visibleKinds(compiler: Compiler, filepath: Filepath): Map<string, NodeSymbol>;
6
6
  export declare function resolveRole(compiler: Compiler, filepath: Filepath, word: string): string | undefined;
7
- export declare function originalHandle(symbol: NodeSymbol): string | undefined;
7
+ export declare function originalHandle(compiler: Compiler, symbol: NodeSymbol, filepath: Filepath): string | undefined;
@@ -7,19 +7,6 @@ import { NodeMetadata } from '../types/symbol/metadata';
7
7
  import { SchemaElement } from '../types/schemaJson';
8
8
  import { NodeSymbol } from '../types/symbol';
9
9
  import { GlobalModule } from './types';
10
- /**
11
- * The DBML vocabulary: the modules a Compiler uses when nobody says otherwise.
12
- *
13
- * The dispatcher tries each in order until one claims the node, so order is meaningful. Each
14
- * time you add a new DBML element, register its module here.
15
- *
16
- * A Compiler may also be built with a different list (see `Compiler`'s second argument). The
17
- * lexer and the parser do not know this vocabulary at all: `parser.ts` has one generic
18
- * `elementDeclaration()` and never mentions `ElementKind`, so another dialect is a different
19
- * array, not a different grammar. Pass a different list and the same front end binds a
20
- * different language, which is how the architecture dialect reuses all of this without forking
21
- * it or widening DBML's own vocabulary by a single word.
22
- */
23
10
  export declare const dbmlModules: GlobalModule[];
24
11
  export declare const archModules: GlobalModule[];
25
12
  export declare function nodeSymbol(this: Compiler, node: SyntaxNode): Report<NodeSymbol> | Report<Unhandled>;
@@ -1,17 +1,7 @@
1
1
  import { Filepath } from '../types/filepath';
2
2
  import { default as Report } from '../types/report';
3
3
  import { SyntaxToken, SyntaxTokenKind } from '../types/tokens';
4
- /**
5
- * Grammar switches the lexer offers a dialect. Off by default, so DBML is untouched.
6
- */
7
4
  export interface LexerOptions {
8
- /**
9
- * Read a `---` fenced block at the very top of a file as one trivia token.
10
- *
11
- * It is Markdown's convention and people expect it for file-level metadata. DBML has no use
12
- * for it, because `Project { ... }` already carries that and its interpreter files any
13
- * unrecognised field as a free-form property. A dialect that wants both says so here.
14
- */
15
5
  allowFrontMatter?: boolean;
16
6
  }
17
7
  export default class Lexer {
@@ -23,13 +13,6 @@ export default class Lexer {
23
13
  private errors;
24
14
  private readonly options;
25
15
  constructor(text: string, filepath: Filepath, options?: LexerOptions);
26
- /**
27
- * Only at offset zero, and only up to the closing fence.
28
- *
29
- * It is consumed character by character like everything else, so `line` and `column` keep
30
- * counting and every token after it still reports where it really is. Lifting the block out
31
- * of the text instead would shift every diagnostic in the file by however many lines it had.
32
- */
33
16
  private scanFrontMatter;
34
17
  private isAtEnd;
35
18
  private advance;
@@ -2,20 +2,7 @@ import { Filepath } from '../types/filepath';
2
2
  import { ProgramNode, SyntaxNodeIdGenerator } from '../types/nodes';
3
3
  import { default as Report } from '../types/report';
4
4
  import { SyntaxToken } from '../types/tokens';
5
- /**
6
- * Grammar switches a dialect may ask for. Every one of these is off by default, so the DBML
7
- * grammar is exactly what it was; a dialect that wants a different shape says so, and the
8
- * difference is one flag rather than a forked parser.
9
- */
10
5
  export interface ParserOptions {
11
- /**
12
- * Allow an element declaration with no body: `Database mongo1` as a complete statement.
13
- *
14
- * DBML has nothing that reads that way, because every DBML element carries something: a Table
15
- * has columns, a Ref has endpoints. An architecture file is the opposite, mostly bare nouns
16
- * with the occasional body, and writing `Database mongo1 { }` on every line to satisfy a
17
- * grammar rule that exists for a different language would be the tail wagging the dog.
18
- */
19
6
  allowBodylessElement?: boolean;
20
7
  }
21
8
  export default class Parser {
@@ -29,7 +29,6 @@ export interface DatabaseExternals {
29
29
  notes: ElementRef[];
30
30
  nodes?: ElementRef[];
31
31
  groups?: ElementRef[];
32
- noteBoxes?: ElementRef[];
33
32
  kinds?: ElementRef[];
34
33
  }
35
34
  /**
@@ -76,7 +75,6 @@ export interface Database {
76
75
  token?: TokenPosition;
77
76
  nodes?: Node[];
78
77
  groups?: Group[];
79
- noteBoxes?: NoteBox[];
80
78
  links?: Link[];
81
79
  kinds?: Kind[];
82
80
  frontMatter?: Record<string, string>;
@@ -109,12 +107,6 @@ export interface Group {
109
107
  } | null;
110
108
  token: TokenPosition;
111
109
  }
112
- export interface NoteBox {
113
- name: string;
114
- alias: string | null;
115
- content: string;
116
- token: TokenPosition;
117
- }
118
110
  export type LinkOp = '>' | '<' | '<>' | '-';
119
111
  export interface Link {
120
112
  from: string;
@@ -359,4 +351,4 @@ export type Project = Record<string, never> | {
359
351
  token: TokenPosition;
360
352
  [index: string & Omit<any, 'name' | 'tables' | 'refs' | 'enums' | 'tableGroups' | 'note' | 'tablePartials' | 'records'>]: string;
361
353
  };
362
- 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 | Node | Group | NoteBox | Link | Kind | ArchSettings;
354
+ 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 | Node | Group | Link | Kind | ArchSettings;
@@ -117,9 +117,10 @@ export declare class MetadataElementMetadata extends NodeMetadata {
117
117
  owners(compiler: Compiler): NodeSymbol[];
118
118
  }
119
119
  export declare class LinkMetadata extends NodeMetadata {
120
- declaration: ElementDeclarationNode;
120
+ declaration: ElementDeclarationNode | AttributeNode;
121
121
  readonly kind = MetadataKind.Link;
122
- constructor(declaration: ElementDeclarationNode);
122
+ constructor(declaration: ElementDeclarationNode | AttributeNode);
123
+ op(): string | undefined;
123
124
  endpoints(compiler: Compiler): [NodeSymbol | undefined, NodeSymbol | undefined];
124
125
  owners(compiler: Compiler): NodeSymbol[];
125
126
  }
@@ -25,7 +25,6 @@ export declare enum SyntaxTokenKind {
25
25
  COLON = "<colon>",
26
26
  SINGLE_LINE_COMMENT = "<single-line-comment>",
27
27
  MULTILINE_COMMENT = "<multiline-comment>",
28
- /** a `---` fenced block at the very top of a file; only a dialect that asks for it gets one */
29
28
  FRONT_MATTER = "<front-matter>",
30
29
  WILDCARD = "<wildcard>"
31
30
  }
@@ -11,7 +11,7 @@ export { SyntaxToken, SyntaxTokenKind, isTriviaToken, isOp, isOpToken, } from '.
11
11
  export { CompileError, CompileErrorCode, } from './core/types/errors';
12
12
  export type { Position, } from './core/types';
13
13
  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 Node, type Group, type NoteBox, type Link, type LinkOp, type Kind, type KindCategory, type ArchSettings, type ArchSettingValue, } from './core/types/schemaJson';
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 Node, type Group, type Link, type LinkOp, type Kind, type KindCategory, type ArchSettings, type ArchSettingValue, } from './core/types/schemaJson';
15
15
  export { type FileKind, ARCH_DIAGRAM_TYPES, isArchDiagramType } from './compiler/queries/files/fileKind';
16
16
  export { BUILTIN_KINDS, RESERVED, isReserved, suggestKind, suggestIcon, type KindSpec, } from './core/arch/vocabulary';
17
17
  export { ICON_ALIAS, ICON_NAMES, isIconName, resolveIcon, } from './core/arch/icons';
@@ -22,14 +22,6 @@ export type { DepSyncOperation, DepSyncEdge, DepEndpointRef } from './compiler/q
22
22
  export type { ElementIdentifier, SchemaIdentifier, TableIdentifier, ColumnIdentifier, EnumIdentifier, EndpointRef, RefIdentifier, DepIdentifier, NoteIdentifier, TableGroupIdentifier, ArchElementIdentifier, ArchLinkIdentifier, } from './compiler/queries/transform';
23
23
  export { dbmlLanguageConfig, dbmlMonarchTokensProvider, } from './services/monarch';
24
24
  export * from './compiler/projectLayout/layout';
25
- /**
26
- * The dialect seam.
27
- *
28
- * A Compiler takes the element vocabulary and the grammar switches it should run with. Pass a
29
- * different module list and the same lexer, parser, file graph, caching and diagnostics bind a
30
- * different language. Nothing below this line changes DBML: `dbmlModules` is what a Compiler
31
- * uses when nobody says otherwise, and every switch in `ParserOptions` is off by default.
32
- */
33
25
  export { dbmlModules } from './core/global_modules';
34
26
  export type { GlobalModule } from './core/global_modules/types';
35
27
  export type { ParserOptions } from './core/parser/parser';
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": "11.0.0-alpha.2",
4
+ "version": "11.0.0-alpha.4",
5
5
  "description": "DBML parser v2",
6
6
  "author": "Holistics <dev@holistics.io>",
7
7
  "license": "Apache-2.0",
@@ -51,5 +51,5 @@
51
51
  "engines": {
52
52
  "node": ">=18"
53
53
  },
54
- "gitHead": "75a0e5bf55149fef937ec7d02e48c170421229ff"
54
+ "gitHead": "40f71a2018dd2a5a9452cd4ba680ef08289fae3a"
55
55
  }