@dbml/parse 9.0.0-alpha.11 → 9.0.0-alpha.13

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,10 @@ import { SyntaxNode, SyntaxNodeIdGenerator } from '../core/types/nodes';
3
3
  import { NodeSymbolIdGenerator, SymbolFactory } from '../core/types/symbol';
4
4
  import { DBMLCompletionItemProvider, DBMLDefinitionProvider, DBMLDiagnosticsProvider, DBMLReferencesProvider } from '../services/index';
5
5
  import { DbmlProjectLayout } from './projectLayout';
6
- import { addDoubleQuoteIfNeeded, escapeString, formatRecordValue, isValidIdentifier, splitQualifiedIdentifier, unescapeString } from './queries/utils';
6
+ import { addDoubleQuoteIfNeeded, escapeString, formatRecordValue, isValidIdentifier, normalizeQualifiedName, splitQualifiedIdentifier, unescapeString } from './queries/utils';
7
7
  export { ScopeKind } from './types';
8
8
  export type { TextEdit } from './queries/transform';
9
- export { addDoubleQuoteIfNeeded, escapeString, formatRecordValue, isValidIdentifier, splitQualifiedIdentifier, unescapeString, };
9
+ export { addDoubleQuoteIfNeeded, escapeString, formatRecordValue, isValidIdentifier, normalizeQualifiedName, splitQualifiedIdentifier, unescapeString, };
10
10
  export default class Compiler {
11
11
  layout: DbmlProjectLayout;
12
12
  readonly nodeIdGenerator: SyntaxNodeIdGenerator;
@@ -29,7 +29,7 @@ export default class Compiler {
29
29
  validateFile: (filepath: Filepath) => import('../core/types/report').default<void>;
30
30
  nodeFullname: (node: SyntaxNode) => import('../core/types/report').default<string[] | undefined> | import('../core/types/report').default<typeof import('..').UNHANDLED>;
31
31
  nodeAlias: (node: SyntaxNode) => import('../core/types/report').default<typeof import('..').UNHANDLED> | import('../core/types/report').default<string | undefined>;
32
- nodeSettings: (node: SyntaxNode) => import('../core/types/report').default<typeof import('..').UNHANDLED> | import('../core/types/report').default<import('../core/utils/validate').Settings>;
32
+ nodeSettings: (node: SyntaxNode) => import('../core/types/report').default<import('../core/utils/validate').Settings> | import('../core/types/report').default<typeof import('..').UNHANDLED>;
33
33
  canonicalName: (filepath: Filepath, symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/report').default<import('./queries/canonicalName').CanonicalName | undefined>;
34
34
  bindNode: (node: SyntaxNode) => import('../core/types/report').default<typeof import('..').UNHANDLED> | import('../core/types/report').default<void>;
35
35
  bindFile: (filepath: Filepath) => import('../core/types/report').default<void>;
@@ -73,6 +73,7 @@ export default class Compiler {
73
73
  nodeAtPosition: (filepath: Filepath, offset: number) => SyntaxNode | import('..').SyntaxToken | undefined;
74
74
  renameTable: (filepath: Filepath, oldName: string | import('..').TableIdentifier, newName: string | import('..').TableIdentifier) => Map<string, string>;
75
75
  updateElementSetting: (filepath: Filepath, target: import('..').ElementIdentifier, settingName: string, value: string | null | undefined) => string;
76
+ updateElementSettingEdit: (filepath: Filepath, target: import('..').ElementIdentifier, settingName: string, value: string | null | undefined) => import('.').TextEdit[];
76
77
  syncDiagramView: (filepath: Filepath, operations: import('..').DiagramViewSyncOperation[], blocks?: import('..').DiagramViewBlock[] | undefined) => {
77
78
  newDbml: string;
78
79
  edits: import('.').TextEdit[];
@@ -1,5 +1,5 @@
1
1
  export { renameTable } from './renameTable';
2
- export { updateElementSetting } from './updateElementSetting';
2
+ export { updateElementSetting, updateElementSettingEdit } from './updateElementSetting';
3
3
  export { syncDiagramView, findDiagramViewBlocks, type DiagramViewSyncOperation, type DiagramViewBlock, } from './syncDiagramView';
4
4
  export { syncDep, findDepBlocks, generateDepBlock, type DepSyncOperation, type DepSyncEdge, type DepEndpointRef, type DepBlock, } from './syncDep';
5
5
  export { applyTextEdits, type TextEdit } from './applyTextEdits';
@@ -1,5 +1,5 @@
1
1
  import { Filepath } from '../../../core/types/filepath';
2
- import { ElementDeclarationNode } from '../../../core/types/nodes';
2
+ import { ElementDeclarationNode, ProgramNode } from '../../../core/types/nodes';
3
3
  import { default as Compiler } from '../../index';
4
4
  import { TextEdit } from './applyTextEdits';
5
5
  export interface DepEndpointRef {
@@ -28,33 +28,27 @@ export interface DepBlock {
28
28
  }
29
29
  export interface InlineDep {
30
30
  edge: DepSyncEdge;
31
- stripStart: number;
32
- stripEnd: number;
31
+ fullStart: number;
32
+ fullEnd: number;
33
33
  }
34
- /**
35
- * Returns every `Dep` block in `source`.
36
- * On any lex or parse error, returns [] - there is no reliable way to read
37
- * dep blocks from malformed DBML (mirrors findDiagramViewBlocks).
38
- */
39
- export declare function findDepBlocks(source: string): DepBlock[];
40
- export declare function findInlineDeps(source: string): InlineDep[];
41
- /**
42
- * Emit a `Dep` block for one edge with a `[color]` setting:
43
- *
44
- * Dep [color: <hex>] {
45
- * <upstream> -> <downstream>
46
- * }
47
- */
48
- export declare function generateDepBlock(edge: DepSyncEdge, color: string): string;
49
34
  /**
50
35
  * Synchronizes `Dep` blocks in the DBML source at `filepath`.
51
- *
52
- * @param filepath The file whose source should be rewritten.
53
- * @param operations Array of create/update operations to apply.
54
- * @param blocks Optional pre-parsed blocks from findDepBlocks.
55
- * @returns The new DBML source and the text edits applied.
36
+ * Applies create/update/remove operations and returns the rewritten source.
56
37
  */
57
38
  export declare function syncDep(this: Compiler, filepath: Filepath, operations: DepSyncOperation[], blocks?: DepBlock[]): {
58
39
  newDbml: string;
59
40
  edits: TextEdit[];
60
41
  };
42
+ /**
43
+ * Returns every standalone `Dep` block in `source`.
44
+ * On lex/parse error returns [] (mirrors findDiagramViewBlocks).
45
+ */
46
+ export declare function findDepBlocks(source: string): DepBlock[];
47
+ /** Returns every inline `[dep: -> target]` setting on columns in `source`. */
48
+ export declare function findInlineDeps(source: string): InlineDep[];
49
+ /** Emit a `Dep` block string for one edge with a `[color]` setting. */
50
+ export declare function generateDepBlock(edge: DepSyncEdge, color: string): string;
51
+ /** Extract `DepBlock[]` from an already-parsed program AST. */
52
+ export declare function depBlocksFromProgram(program: ProgramNode): DepBlock[];
53
+ /** Extract `InlineDep[]` from an already-parsed program AST. */
54
+ export declare function inlineDepsFromProgram(source: string, program: ProgramNode): InlineDep[];
@@ -1,4 +1,6 @@
1
1
  import { Filepath } from '../../../core/types/filepath';
2
2
  import { default as Compiler } from '../../index';
3
+ import { TextEdit } from './applyTextEdits';
3
4
  import { ElementIdentifier } from './types';
5
+ export declare function updateElementSettingEdit(this: Compiler, filepath: Filepath, target: ElementIdentifier, settingName: string, value: string | null | undefined): TextEdit[];
4
6
  export declare function updateElementSetting(this: Compiler, filepath: Filepath, target: ElementIdentifier, settingName: string, value: string | null | undefined): string;
@@ -0,0 +1,26 @@
1
+ import { Filepath } from '../../../../core/types/filepath';
2
+ import { NodeSymbol, SymbolKind } from '../../../../core/types/symbol';
3
+ import { default as Compiler } from '../../../index';
4
+ import { EndpointRef } from '../types';
5
+ export type { ElementIdentifier } from '../types';
6
+ export { findRefDefinition, type InlineRef, type StandaloneRef } from './ref';
7
+ export declare function normalizeSchema(schema?: string | null): string;
8
+ export declare function endpointsEqual(left: EndpointRef, right: EndpointRef): boolean;
9
+ export declare function endpointMatches(candidate: EndpointRef, target: EndpointRef): boolean;
10
+ export declare function normalizeTableName(input: string | {
11
+ schema?: string;
12
+ table: string;
13
+ }): {
14
+ schema: string;
15
+ table: string;
16
+ };
17
+ /**
18
+ * Looks up an element symbol by its qualified name and kind.
19
+ */
20
+ export declare function lookupElementSymbol(compiler: Compiler, filepath: Filepath, schema: string, name: string, kind?: SymbolKind): NodeSymbol | undefined;
21
+ /**
22
+ * Removes surrounding double quotes from a string if present.
23
+ */
24
+ export declare function stripQuotes(str: string): string;
25
+ export declare function formatEndpoint(ep: EndpointRef): string;
26
+ export declare function formatSetting(name: string, value: string | null | undefined): string;
@@ -0,0 +1,15 @@
1
+ import { FunctionApplicationNode } from '../../../../core/types/nodes';
2
+ import { Filepath } from '../../../../core/types/filepath';
3
+ import { default as Compiler } from '../../../index';
4
+ import { RefIdentifier } from '../types';
5
+ export interface InlineRef {
6
+ kind: 'inline';
7
+ op: string;
8
+ fullStart: number;
9
+ fullEnd: number;
10
+ }
11
+ export interface StandaloneRef {
12
+ kind: 'standalone';
13
+ node: FunctionApplicationNode;
14
+ }
15
+ export declare function findRefDefinition(compiler: Compiler, filepath: Filepath, target: RefIdentifier): InlineRef | StandaloneRef | undefined;
@@ -35,6 +35,7 @@ export declare function isValidIdentifier(name: string): boolean;
35
35
  * addDoubleQuoteIfNeeded('user-name') => '"user-name"'
36
36
  */
37
37
  export declare function addDoubleQuoteIfNeeded(identifier: string): string;
38
+ export declare function normalizeQualifiedName(...parts: string[]): string;
38
39
  /**
39
40
  * Unescapes a string by processing escape sequences.
40
41
  * Handles escaped quotes (\"), common escape sequences, unicode (\uHHHH), and arbitrary escapes.
@@ -2,25 +2,12 @@ import { default as Compiler } from '../../../../../compiler/index';
2
2
  import { CompileWarning } from '../../../../types/errors';
3
3
  import { RecordValue, TableRecord } from '../../../../types/schemaJson';
4
4
  import { ColumnSymbol } from '../../../../types/symbol';
5
- export interface ColumnInfo {
6
- name: string;
7
- pk: boolean;
8
- unique: boolean;
9
- increment: boolean;
10
- notNull: boolean;
11
- dbdefault?: {
12
- value: string | number;
13
- type: string;
14
- };
15
- typeName: string;
16
- }
17
- export declare function columnInfoFromSymbol(col: ColumnSymbol, compiler: Compiler): ColumnInfo;
18
5
  export declare function toKeyedRows(record: TableRecord): Record<string, RecordValue>[];
19
6
  export declare function makeTableKey(schema: string | null, table: string): string;
20
- export declare function extractKeyValueWithDefault(row: Record<string, RecordValue>, columnNames: string[], columns?: (ColumnInfo | undefined)[]): string;
21
- export declare function hasNullWithoutDefaultInKey(row: Record<string, RecordValue>, columnNames: string[], columns?: (ColumnInfo | undefined)[]): boolean;
22
- export declare function isAutoIncrementColumn(column: ColumnInfo): boolean;
7
+ export declare function extractKeyValueWithDefault(compiler: Compiler, row: Record<string, RecordValue>, columns: ColumnSymbol[]): string;
8
+ export declare function hasNullWithoutDefaultInKey(compiler: Compiler, row: Record<string, RecordValue>, columns: ColumnSymbol[]): boolean;
23
9
  export declare function formatFullColumnName(schemaName: string | null, tableName: string, columnName: string): string;
24
10
  export declare function formatFullColumnNames(schemaName: string | null, tableName: string, columnNames: string[]): string;
25
- export declare function formatValues(row: Record<string, RecordValue>, columnNames: string[]): string;
11
+ export declare function formatValues(compiler: Compiler, row: Record<string, RecordValue>, columns: ColumnSymbol[]): string;
12
+ export declare function getDiagnosticAnchorValues(row: Record<string, RecordValue>, columnNames: string[]): RecordValue[];
26
13
  export declare function createConstraintWarning(compiler: Compiler, recordValue: RecordValue, message: string): CompileWarning;
@@ -2,7 +2,7 @@ import { default as Compiler } from '../../compiler';
2
2
  import { RelationCardinality } from '../types';
3
3
  import { PrimaryExpressionNode, SyntaxNode, VariableNode } from '../types/nodes';
4
4
  import { default as Report } from '../types/report';
5
- import { NodeSymbol } from '../types/symbol';
5
+ import { SymbolKind, NodeSymbol } from '../types/symbol';
6
6
  export declare function shouldInterpretNode(compiler: Compiler, node: SyntaxNode): boolean;
7
7
  export declare function getNodeMemberSymbols(compiler: Compiler, node: SyntaxNode): Report<NodeSymbol[]>;
8
8
  export declare function scanNonListNodeForBinding(node?: SyntaxNode): {
@@ -14,4 +14,5 @@ export declare function scanNonListNodeForBinding(node?: SyntaxNode): {
14
14
  })[];
15
15
  }[];
16
16
  export declare function nodeRefereeOfLeftExpression(compiler: Compiler, node: SyntaxNode): NodeSymbol | undefined;
17
+ export declare function nodeRefereeOfEndpoint(compiler: Compiler, globalSymbol: NodeSymbol, node: SyntaxNode, terminalKind: SymbolKind.Column | SymbolKind.Table): Report<NodeSymbol | undefined>;
17
18
  export declare function getMultiplicities(op: string): [RelationCardinality, RelationCardinality] | undefined;
@@ -150,6 +150,7 @@ export declare class ColumnSymbol extends NodeSymbol {
150
150
  pk(compiler: Compiler): boolean;
151
151
  unique(compiler: Compiler): boolean;
152
152
  nullable(compiler: Compiler): boolean | undefined;
153
+ isIncrementSet(compiler: Compiler): boolean;
153
154
  increment(compiler: Compiler): boolean;
154
155
  default(compiler: Compiler): {
155
156
  type: 'number' | 'string' | 'boolean' | 'expression';
@@ -24,6 +24,7 @@ export declare function isValidPartialInjection(node?: SyntaxNode): node is Pref
24
24
  };
25
25
  };
26
26
  export declare function isRelationshipOp(op?: string): boolean;
27
+ export declare function isDependencyOp(op?: string): boolean;
27
28
  export declare function isValidColor(value?: SyntaxNode): boolean;
28
29
  export declare function isValidDefaultValue(value?: SyntaxNode): boolean;
29
30
  export type SignedNumberExpression = (PrimaryExpressionNode & {
@@ -38,6 +39,7 @@ export type SignedNumberExpression = (PrimaryExpressionNode & {
38
39
  });
39
40
  export declare function isExpressionASignedNumberExpression(value?: SyntaxNode): value is SignedNumberExpression;
40
41
  export declare function isUnaryRelationship(value?: SyntaxNode): value is PrefixExpressionNode;
42
+ export declare function isUnaryDependency(value?: SyntaxNode): value is PrefixExpressionNode;
41
43
  export declare function isTupleOfVariables(value?: SyntaxNode): value is TupleExpressionNode & {
42
44
  elementList: (PrimaryExpressionNode & {
43
45
  expression: VariableNode;
@@ -10,7 +10,7 @@ export * from './core/types/nodes';
10
10
  export { SyntaxToken, SyntaxTokenKind, isTriviaToken, isOp, isOpToken, } from './core/types/tokens';
11
11
  export { CompileError, CompileErrorCode, } from './core/types/errors';
12
12
  export type { Position, } from './core/types';
13
- export { ScopeKind, splitQualifiedIdentifier, unescapeString, escapeString, formatRecordValue, isValidIdentifier, addDoubleQuoteIfNeeded, } from './compiler/index';
13
+ export { ScopeKind, splitQualifiedIdentifier, unescapeString, escapeString, formatRecordValue, isValidIdentifier, addDoubleQuoteIfNeeded, normalizeQualifiedName, } from './compiler/index';
14
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 RelationCardinality, 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, } from './core/types/schemaJson';
15
15
  export type { DiagramViewSyncOperation, DiagramViewBlock, TextEdit, } from './compiler/queries/transform';
16
16
  export { findDiagramViewBlocks, findDepBlocks } from './compiler/queries/transform';
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": "9.0.0-alpha.11",
4
+ "version": "9.0.0-alpha.13",
5
5
  "description": "DBML parser v2",
6
6
  "author": "Holistics <dev@holistics.io>",
7
7
  "license": "Apache-2.0",
@@ -50,5 +50,5 @@
50
50
  "engines": {
51
51
  "node": ">=18"
52
52
  },
53
- "gitHead": "da99890d362342d38ec4044620962d0ebaddb2ee"
53
+ "gitHead": "aad3f5808c07679bd201d4da15561beb8abf05f1"
54
54
  }
@@ -1,21 +0,0 @@
1
- import { Filepath } from '../../../core/types/filepath';
2
- import { NodeSymbol, SymbolKind } from '../../../core/types/symbol';
3
- import { default as Compiler } from '../../index';
4
- import { EndpointRef } from './types';
5
- export type { ElementIdentifier } from './types';
6
- export declare function endpointsEqual(a: EndpointRef, b: EndpointRef): boolean;
7
- export declare function normalizeTableName(input: string | {
8
- schema?: string;
9
- table: string;
10
- }): {
11
- schema: string;
12
- table: string;
13
- };
14
- /**
15
- * Looks up an element symbol by its qualified name and kind.
16
- */
17
- export declare function lookupElementSymbol(compiler: Compiler, filepath: Filepath, schema: string, name: string, kind?: SymbolKind): NodeSymbol | undefined;
18
- /**
19
- * Removes surrounding double quotes from a string if present.
20
- */
21
- export declare function stripQuotes(str: string): string;