@dbml/parse 9.0.0-alpha.2 → 9.0.0-alpha.21
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.
- package/dist/dbml-parse.js +29 -22
- package/dist/dbml-parse.mjs +8850 -8419
- package/dist/src/compiler/index.d.ts +9 -10
- package/dist/src/compiler/queries/transform/index.d.ts +2 -1
- package/dist/src/compiler/queries/transform/renameTable.d.ts +2 -2
- package/dist/src/compiler/queries/transform/syncDep.d.ts +24 -60
- package/dist/src/compiler/queries/transform/types.d.ts +48 -0
- package/dist/src/compiler/queries/transform/updateElementSetting.d.ts +6 -0
- package/dist/src/compiler/queries/transform/utils/index.d.ts +26 -0
- package/dist/src/compiler/queries/transform/utils/ref.d.ts +15 -0
- package/dist/src/compiler/queries/utils.d.ts +6 -0
- package/dist/src/compiler/types.d.ts +8 -7
- package/dist/src/core/global_modules/dep/bind.d.ts +3 -0
- package/dist/src/core/global_modules/dep/interpret.d.ts +0 -16
- package/dist/src/core/global_modules/program/interpret.d.ts +0 -2
- package/dist/src/core/global_modules/program/utils/dep.d.ts +4 -0
- package/dist/src/core/global_modules/program/utils/external.d.ts +3 -0
- package/dist/src/core/global_modules/program/utils/index.d.ts +3 -0
- package/dist/src/core/global_modules/program/utils/records.d.ts +6 -0
- package/dist/src/core/global_modules/records/utils/constraints/helper.d.ts +4 -17
- package/dist/src/core/global_modules/utils.d.ts +2 -1
- package/dist/src/core/local_modules/dep/validate.d.ts +1 -0
- package/dist/src/core/types/errors.d.ts +7 -3
- package/dist/src/core/types/schemaJson.d.ts +5 -2
- package/dist/src/core/types/symbol/symbols.d.ts +1 -0
- package/dist/src/core/utils/expression.d.ts +2 -1
- package/dist/src/core/utils/note.d.ts +18 -0
- package/dist/src/core/utils/setting.d.ts +16 -0
- package/dist/src/core/utils/validate.d.ts +2 -0
- package/dist/src/index.d.ts +4 -1
- package/package.json +2 -2
- package/dist/src/compiler/queries/transform/utils.d.ts +0 -23
- package/dist/src/core/global_modules/program/utils.d.ts +0 -3
|
@@ -3,11 +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 {
|
|
7
|
-
import { addDoubleQuoteIfNeeded, escapeString, formatRecordValue, isValidIdentifier, splitQualifiedIdentifier, unescapeString } from './queries/utils';
|
|
6
|
+
import { addDoubleQuoteIfNeeded, escapeString, formatRecordValue, isValidIdentifier, normalizeQualifiedName, splitQualifiedIdentifier, unescapeString } from './queries/utils';
|
|
8
7
|
export { ScopeKind } from './types';
|
|
9
|
-
export type {
|
|
10
|
-
export { addDoubleQuoteIfNeeded, escapeString, formatRecordValue, isValidIdentifier, splitQualifiedIdentifier, unescapeString,
|
|
8
|
+
export type { TextEdit } from './queries/transform';
|
|
9
|
+
export { addDoubleQuoteIfNeeded, escapeString, formatRecordValue, isValidIdentifier, normalizeQualifiedName, splitQualifiedIdentifier, unescapeString, };
|
|
11
10
|
export default class Compiler {
|
|
12
11
|
layout: DbmlProjectLayout;
|
|
13
12
|
readonly nodeIdGenerator: SyntaxNodeIdGenerator;
|
|
@@ -30,7 +29,7 @@ export default class Compiler {
|
|
|
30
29
|
validateFile: (filepath: Filepath) => import('../core/types/report').default<void>;
|
|
31
30
|
nodeFullname: (node: SyntaxNode) => import('../core/types/report').default<string[] | undefined> | import('../core/types/report').default<typeof import('..').UNHANDLED>;
|
|
32
31
|
nodeAlias: (node: SyntaxNode) => import('../core/types/report').default<typeof import('..').UNHANDLED> | import('../core/types/report').default<string | undefined>;
|
|
33
|
-
nodeSettings: (node: SyntaxNode) => import('../core/types/report').default<
|
|
32
|
+
nodeSettings: (node: SyntaxNode) => import('../core/types/report').default<import('../core/utils/validate').Settings> | import('../core/types/report').default<typeof import('..').UNHANDLED>;
|
|
34
33
|
canonicalName: (filepath: Filepath, symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/report').default<import('./queries/canonicalName').CanonicalName | undefined>;
|
|
35
34
|
bindNode: (node: SyntaxNode) => import('../core/types/report').default<typeof import('..').UNHANDLED> | import('../core/types/report').default<void>;
|
|
36
35
|
bindFile: (filepath: Filepath) => import('../core/types/report').default<void>;
|
|
@@ -72,17 +71,17 @@ export default class Compiler {
|
|
|
72
71
|
};
|
|
73
72
|
}>;
|
|
74
73
|
nodeAtPosition: (filepath: Filepath, offset: number) => SyntaxNode | import('..').SyntaxToken | undefined;
|
|
75
|
-
renameTable: (filepath: Filepath, oldName: import('
|
|
76
|
-
|
|
74
|
+
renameTable: (filepath: Filepath, oldName: string | import('..').TableIdentifier, newName: string | import('..').TableIdentifier) => Map<string, string>;
|
|
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[];
|
|
77
|
+
syncDiagramView: (filepath: Filepath, operations: import('..').DiagramViewSyncOperation[], blocks?: import('..').DiagramViewBlock[] | undefined) => {
|
|
77
78
|
newDbml: string;
|
|
78
79
|
edits: import('.').TextEdit[];
|
|
79
80
|
};
|
|
80
|
-
|
|
81
|
-
syncDep: (filepath: Filepath, operations: import('..').DepSyncOperation[], blocks?: DepBlock[] | undefined) => {
|
|
81
|
+
syncDep: (filepath: Filepath, operations: import('..').DepSyncOperation[], blocks?: import('..').DepBlock[] | undefined) => {
|
|
82
82
|
newDbml: string;
|
|
83
83
|
edits: import('.').TextEdit[];
|
|
84
84
|
};
|
|
85
|
-
findDepBlocks(filepath: Filepath): DepBlock[];
|
|
86
85
|
readonly token: {
|
|
87
86
|
invalidStream: (filepath: Filepath) => readonly import('..').SyntaxToken[];
|
|
88
87
|
flatStream: (filepath: Filepath) => readonly import('..').SyntaxToken[];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { renameTable } from './renameTable';
|
|
2
|
+
export { updateElementSetting, updateElementSettingEdit } from './updateElementSetting';
|
|
2
3
|
export { syncDiagramView, findDiagramViewBlocks, type DiagramViewSyncOperation, type DiagramViewBlock, } from './syncDiagramView';
|
|
3
4
|
export { syncDep, findDepBlocks, generateDepBlock, type DepSyncOperation, type DepSyncEdge, type DepEndpointRef, type DepBlock, } from './syncDep';
|
|
4
5
|
export { applyTextEdits, type TextEdit } from './applyTextEdits';
|
|
5
|
-
export {
|
|
6
|
+
export type { ElementIdentifier, SchemaIdentifier, TableIdentifier, ColumnIdentifier, EnumIdentifier, EndpointRef, RefIdentifier, DepIdentifier, NoteIdentifier, TableGroupIdentifier, } from './types';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Filepath } from '../../../core/types/filepath';
|
|
2
2
|
import { default as Compiler } from '../../index';
|
|
3
|
-
import {
|
|
3
|
+
import { TableIdentifier } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* Renames a table across every file in the project layout.
|
|
6
6
|
*
|
|
@@ -23,4 +23,4 @@ import { TableNameInput } from './utils';
|
|
|
23
23
|
* only the files that were actually changed by the rename. An empty map
|
|
24
24
|
* indicates a no-op (lookup miss, name collision, or alias rename attempt).
|
|
25
25
|
*/
|
|
26
|
-
export declare function renameTable(this: Compiler, filepath: Filepath, oldName:
|
|
26
|
+
export declare function renameTable(this: Compiler, filepath: Filepath, oldName: string | TableIdentifier, newName: string | TableIdentifier): Map<string, string>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Filepath } from '../../../core/types/filepath';
|
|
2
|
+
import { ElementDeclarationNode, ProgramNode } from '../../../core/types/nodes';
|
|
2
3
|
import { default as Compiler } from '../../index';
|
|
3
4
|
import { TextEdit } from './applyTextEdits';
|
|
4
|
-
/** One endpoint of a dep edge. `fieldNames` is empty for a table-level edge. */
|
|
5
5
|
export interface DepEndpointRef {
|
|
6
6
|
schemaName?: string | null;
|
|
7
7
|
tableName: string;
|
|
@@ -12,79 +12,43 @@ export interface DepSyncEdge {
|
|
|
12
12
|
downstream: DepEndpointRef;
|
|
13
13
|
}
|
|
14
14
|
export interface DepSyncOperation {
|
|
15
|
-
operation: 'create' | 'update';
|
|
16
|
-
/** The edge that identifies the target block (table-level: empty
|
|
15
|
+
operation: 'create' | 'update' | 'remove';
|
|
16
|
+
/** The edge that identifies the target block (table-level: empty fields). */
|
|
17
17
|
edge: DepSyncEdge;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
* `kind` says how to overwrite it:
|
|
24
|
-
* - `attribute` -> replace just the `color: <hex>` attribute at `start..end`
|
|
25
|
-
* (inside a `[...]` list that may hold other settings).
|
|
26
|
-
* - `subDeclaration` -> replace the whole `color: <hex>` body line at
|
|
27
|
-
* `start..end`.
|
|
28
|
-
*/
|
|
29
|
-
interface ColorSetting {
|
|
30
|
-
kind: 'attribute' | 'subDeclaration';
|
|
31
|
-
start: number;
|
|
32
|
-
end: number;
|
|
18
|
+
/** Set to a value to create/update, null to remove, undefined to leave unchanged. */
|
|
19
|
+
color?: string | null;
|
|
20
|
+
/** Set to a value to create/update, null to remove, undefined to leave unchanged. */
|
|
21
|
+
note?: string | null;
|
|
33
22
|
}
|
|
34
23
|
export interface DepBlock {
|
|
35
24
|
startIndex: number;
|
|
36
25
|
endIndex: number;
|
|
26
|
+
declaration: ElementDeclarationNode;
|
|
37
27
|
edges: DepSyncEdge[];
|
|
38
|
-
/**
|
|
39
|
-
* An existing header `[...]` attribute list (without a color setting), so a
|
|
40
|
-
* color can be inserted into it instead of adding a second `[...]`.
|
|
41
|
-
* Records the offset just before the list's closing `]`.
|
|
42
|
-
*/
|
|
43
|
-
attributeListInsertAt?: number;
|
|
44
|
-
attributeListIsEmpty?: boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Offset of the block body `{` - where to add a header `[color: ...]` for a
|
|
47
|
-
* block-form Dep that has no attribute list.
|
|
48
|
-
*/
|
|
49
|
-
bodyOpenAt?: number;
|
|
50
|
-
/**
|
|
51
|
-
* End offset of a short-form (`Dep: a -> b`) body that has no setting list -
|
|
52
|
-
* where to append ` [color: ...]`.
|
|
53
|
-
*/
|
|
54
|
-
shortFormEnd?: number;
|
|
55
|
-
/** The existing color setting (header list, inline list, or sub-declaration), if any. */
|
|
56
|
-
color?: ColorSetting;
|
|
57
28
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Returns every `Dep` block in `source`.
|
|
60
|
-
* On any lex or parse error, returns [] - there is no reliable way to read
|
|
61
|
-
* dep blocks from malformed DBML (mirrors findDiagramViewBlocks).
|
|
62
|
-
*/
|
|
63
|
-
export declare function findDepBlocks(source: string): DepBlock[];
|
|
64
29
|
export interface InlineDep {
|
|
65
30
|
edge: DepSyncEdge;
|
|
66
|
-
|
|
67
|
-
|
|
31
|
+
fullStart: number;
|
|
32
|
+
fullEnd: number;
|
|
68
33
|
}
|
|
69
|
-
export declare function findInlineDeps(source: string): InlineDep[];
|
|
70
|
-
/**
|
|
71
|
-
* Emit a `Dep` block for one edge with a `[color]` setting:
|
|
72
|
-
*
|
|
73
|
-
* Dep [color: <hex>] {
|
|
74
|
-
* <upstream> -> <downstream>
|
|
75
|
-
* }
|
|
76
|
-
*/
|
|
77
|
-
export declare function generateDepBlock(edge: DepSyncEdge, color: string): string;
|
|
78
34
|
/**
|
|
79
35
|
* Synchronizes `Dep` blocks in the DBML source at `filepath`.
|
|
80
|
-
*
|
|
81
|
-
* @param filepath The file whose source should be rewritten.
|
|
82
|
-
* @param operations Array of create/update operations to apply.
|
|
83
|
-
* @param blocks Optional pre-parsed blocks from findDepBlocks.
|
|
84
|
-
* @returns The new DBML source and the text edits applied.
|
|
36
|
+
* Applies create/update/remove operations and returns the rewritten source.
|
|
85
37
|
*/
|
|
86
38
|
export declare function syncDep(this: Compiler, filepath: Filepath, operations: DepSyncOperation[], blocks?: DepBlock[]): {
|
|
87
39
|
newDbml: string;
|
|
88
40
|
edits: TextEdit[];
|
|
89
41
|
};
|
|
90
|
-
|
|
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[];
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { SymbolKind } from '../../../core/types/symbol';
|
|
2
|
+
import { MetadataKind } from '../../../core/types/symbol/metadata';
|
|
3
|
+
export type ElementIdentifier = (SchemaIdentifier | TableIdentifier | ColumnIdentifier | EnumIdentifier | RefIdentifier | DepIdentifier | NoteIdentifier | TableGroupIdentifier) & {
|
|
4
|
+
kind: string;
|
|
5
|
+
};
|
|
6
|
+
export interface SchemaIdentifier {
|
|
7
|
+
kind?: typeof SymbolKind.Schema;
|
|
8
|
+
schema: string;
|
|
9
|
+
}
|
|
10
|
+
export interface TableIdentifier {
|
|
11
|
+
kind?: typeof SymbolKind.Table;
|
|
12
|
+
schema?: string;
|
|
13
|
+
table: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ColumnIdentifier {
|
|
16
|
+
kind?: typeof SymbolKind.Column;
|
|
17
|
+
schema?: string;
|
|
18
|
+
table: string;
|
|
19
|
+
column: string;
|
|
20
|
+
}
|
|
21
|
+
export interface EnumIdentifier {
|
|
22
|
+
kind?: typeof SymbolKind.Enum;
|
|
23
|
+
schema?: string;
|
|
24
|
+
name: string;
|
|
25
|
+
}
|
|
26
|
+
export interface EndpointRef {
|
|
27
|
+
schemaName?: string | null;
|
|
28
|
+
tableName: string;
|
|
29
|
+
fieldNames?: string[];
|
|
30
|
+
}
|
|
31
|
+
export interface RefIdentifier {
|
|
32
|
+
kind?: typeof MetadataKind.Ref;
|
|
33
|
+
endpoints: [EndpointRef, EndpointRef];
|
|
34
|
+
}
|
|
35
|
+
export interface DepIdentifier {
|
|
36
|
+
kind?: typeof MetadataKind.Dep;
|
|
37
|
+
upstream: EndpointRef;
|
|
38
|
+
downstream: EndpointRef;
|
|
39
|
+
}
|
|
40
|
+
export interface NoteIdentifier {
|
|
41
|
+
kind?: typeof SymbolKind.StickyNote;
|
|
42
|
+
name: string;
|
|
43
|
+
}
|
|
44
|
+
export interface TableGroupIdentifier {
|
|
45
|
+
kind?: typeof SymbolKind.TableGroup;
|
|
46
|
+
schema?: string;
|
|
47
|
+
name: string;
|
|
48
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Filepath } from '../../../core/types/filepath';
|
|
2
|
+
import { default as Compiler } from '../../index';
|
|
3
|
+
import { TextEdit } from './applyTextEdits';
|
|
4
|
+
import { ElementIdentifier } from './types';
|
|
5
|
+
export declare function updateElementSettingEdit(this: Compiler, filepath: Filepath, target: ElementIdentifier, settingName: string, value: string | null | undefined): TextEdit[];
|
|
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.
|
|
@@ -99,3 +100,8 @@ export declare function formatRecordValue(recordValue: {
|
|
|
99
100
|
export declare function splitQualifiedIdentifier(identifier: string): string[];
|
|
100
101
|
export declare function collectTransitiveDependencies(compiler: Compiler, entrypoints: Filepath[]): Filepath[];
|
|
101
102
|
export declare function allVisibleMembers(compiler: Compiler): Report<NodeSymbol[]>;
|
|
103
|
+
/**
|
|
104
|
+
* Wraps a note value in the appropriate DBML quote style.
|
|
105
|
+
* Uses triple quotes for multiline content, single quotes otherwise.
|
|
106
|
+
*/
|
|
107
|
+
export declare function quoteNoteValue(value: string): string;
|
|
@@ -5,11 +5,12 @@ export declare const enum ScopeKind {
|
|
|
5
5
|
INDEXES = 3,
|
|
6
6
|
NOTE = 4,
|
|
7
7
|
REF = 5,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
DEP = 6,
|
|
9
|
+
PROJECT = 7,
|
|
10
|
+
CUSTOM = 8,
|
|
11
|
+
TOPLEVEL = 9,
|
|
12
|
+
TABLEPARTIAL = 10,
|
|
13
|
+
CHECKS = 11,
|
|
14
|
+
RECORDS = 12,
|
|
15
|
+
DIAGRAMVIEW = 13
|
|
15
16
|
}
|
|
@@ -12,22 +12,6 @@ export declare class DepInterpreter {
|
|
|
12
12
|
interpret(): Report<Dep>;
|
|
13
13
|
private interpretName;
|
|
14
14
|
private interpretEdges;
|
|
15
|
-
/**
|
|
16
|
-
* Read settings into `dep.note` and `dep.custom`.
|
|
17
|
-
*
|
|
18
|
-
* Settings come from THREE sources, in this order:
|
|
19
|
-
* 1. The top-level attribute list on the Dep header
|
|
20
|
-
* (e.g. `Dep my_block [color: 'blue'] { ... }`).
|
|
21
|
-
* 2. Per-field setting lists inside the body
|
|
22
|
-
* (e.g. `Dep { a -> b [note: 'x'] }`).
|
|
23
|
-
* 3. Sub-element declarations inside the body
|
|
24
|
-
* (e.g. `Dep { a -> b; note: 'x'; materialized: 'view' }`).
|
|
25
|
-
*
|
|
26
|
-
* All three sources write into the same `custom` object (with `note`
|
|
27
|
-
* routed to the typed slot instead). Precedence is last-write-wins by
|
|
28
|
-
* virtue of plain object assignment — settings later in the source
|
|
29
|
-
* file overwrite earlier ones with the same key.
|
|
30
|
-
*/
|
|
31
15
|
private interpretSettings;
|
|
32
16
|
private consumeSettings;
|
|
33
17
|
private extractAttrValue;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { default as Compiler } from '../../../../compiler/index';
|
|
2
|
+
import { CompileWarning } from '../../../types/errors';
|
|
3
|
+
import { Filepath } from '../../../types/filepath';
|
|
4
|
+
import { Ref } from '../../../types/schemaJson';
|
|
5
|
+
import { ProgramSymbol } from '../../../types/symbol';
|
|
6
|
+
export declare function validateRecords(compiler: Compiler, programSymbol: ProgramSymbol, refs: Ref[], filepath: Filepath): CompileWarning[];
|
|
@@ -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>,
|
|
21
|
-
export declare function hasNullWithoutDefaultInKey(row: Record<string, RecordValue>,
|
|
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>,
|
|
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;
|
|
@@ -8,6 +8,7 @@ export default class DepValidator {
|
|
|
8
8
|
private compiler;
|
|
9
9
|
constructor(compiler: Compiler, declarationNode: ElementDeclarationNode);
|
|
10
10
|
validate(): CompileError[];
|
|
11
|
+
private validateSettings;
|
|
11
12
|
private validateContext;
|
|
12
13
|
private validateName;
|
|
13
14
|
private validateAlias;
|
|
@@ -113,9 +113,13 @@ export declare enum CompileErrorCode {
|
|
|
113
113
|
UNSUPPORTED = 5000,
|
|
114
114
|
CIRCULAR_REF = 5001,
|
|
115
115
|
SAME_ENDPOINT = 5002,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
DEP_SELF_LOOP = 5003,
|
|
117
|
+
DEP_MIXED_DOWNSTREAM_TABLES = 5004,
|
|
118
|
+
DEP_DUPLICATE_DOWNSTREAM_TABLE = 5005,
|
|
119
|
+
DEP_MIXED_LEVEL = 5006,
|
|
120
|
+
UNEQUAL_FIELDS_BINARY_REF = 5007,
|
|
121
|
+
CONFLICTING_SETTING = 5008,
|
|
122
|
+
TABLE_REAPPEAR_IN_TABLEGROUP = 5009
|
|
119
123
|
}
|
|
120
124
|
export declare class CompileError extends Error {
|
|
121
125
|
code: Readonly<CompileErrorCode>;
|
|
@@ -182,7 +182,7 @@ export interface Dep {
|
|
|
182
182
|
value: string;
|
|
183
183
|
token: TokenPosition;
|
|
184
184
|
};
|
|
185
|
-
|
|
185
|
+
metadata?: Record<string, string | number | boolean | null>;
|
|
186
186
|
token: TokenPosition;
|
|
187
187
|
}
|
|
188
188
|
export interface DepEdge {
|
|
@@ -196,11 +196,14 @@ export interface DepEndpoint {
|
|
|
196
196
|
fieldNames: string[];
|
|
197
197
|
token: TokenPosition;
|
|
198
198
|
}
|
|
199
|
+
export declare const DEP_DOWNSTREAM: "->";
|
|
200
|
+
export declare const DEP_UPSTREAM: "<-";
|
|
201
|
+
export type DepDirection = typeof DEP_DOWNSTREAM | typeof DEP_UPSTREAM;
|
|
199
202
|
export interface InlineDep {
|
|
200
203
|
schemaName: string | null;
|
|
201
204
|
tableName: string;
|
|
202
205
|
fieldNames: string[];
|
|
203
|
-
direction:
|
|
206
|
+
direction: DepDirection;
|
|
204
207
|
token: TokenPosition;
|
|
205
208
|
}
|
|
206
209
|
export interface Enum {
|
|
@@ -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';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ElementDeclarationNode, FunctionApplicationNode, FunctionExpressionNode, IdentifierStreamNode, PrimaryExpressionNode, SyntaxNode, TupleExpressionNode, VariableNode } from '../types/nodes';
|
|
1
|
+
import { AttributeNode, ElementDeclarationNode, FunctionApplicationNode, FunctionExpressionNode, IdentifierStreamNode, PrimaryExpressionNode, SyntaxNode, TupleExpressionNode, VariableNode } from '../types/nodes';
|
|
2
2
|
import { SyntaxToken } from '../types/tokens';
|
|
3
3
|
export declare function extractVariableNode(value?: unknown): SyntaxToken | undefined;
|
|
4
4
|
export declare function extractStringFromIdentifierStream(stream?: IdentifierStreamNode): string | undefined;
|
|
@@ -35,3 +35,4 @@ export declare function extractVariableFromExpression(node?: SyntaxNode): string
|
|
|
35
35
|
export declare function extractVarNameFromPrimaryVariable(node?: PrimaryExpressionNode & {
|
|
36
36
|
expression: VariableNode;
|
|
37
37
|
}): string | undefined;
|
|
38
|
+
export declare function extractSettingName(attr: AttributeNode): string | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SyntaxNode } from '../types/nodes';
|
|
2
|
+
import { TextEdit } from '../../compiler/queries/transform/applyTextEdits';
|
|
3
|
+
/**
|
|
4
|
+
* Produces a TextEdit that updates an existing note's value.
|
|
5
|
+
* Returns undefined if no note exists.
|
|
6
|
+
*/
|
|
7
|
+
export declare function updateNoteEdit(declaration: SyntaxNode, newValue: string): TextEdit | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Produces a TextEdit that removes an existing note.
|
|
10
|
+
* Returns undefined if no note exists.
|
|
11
|
+
*/
|
|
12
|
+
export declare function removeNoteEdit(declaration: SyntaxNode): TextEdit | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Produces a TextEdit that adds a note to an element.
|
|
15
|
+
* Prioritizes body note form for block elements, falls back to setting attribute.
|
|
16
|
+
* Returns undefined if a note already exists.
|
|
17
|
+
*/
|
|
18
|
+
export declare function addNoteEdit(declaration: SyntaxNode, value: string): TextEdit | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ListExpressionNode, AttributeNode, ElementDeclarationNode, SyntaxNode } from '../types/nodes';
|
|
2
|
+
import { TextEdit } from '../../compiler/queries/transform/applyTextEdits';
|
|
3
|
+
export type SettingLocation = {
|
|
4
|
+
kind: 'attribute';
|
|
5
|
+
settingsList: ListExpressionNode;
|
|
6
|
+
settingNode: AttributeNode;
|
|
7
|
+
settingIndex: number;
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'body';
|
|
10
|
+
declaration: ElementDeclarationNode;
|
|
11
|
+
} | undefined;
|
|
12
|
+
export declare function findSetting(declaration: SyntaxNode, settingName: string): SettingLocation;
|
|
13
|
+
export declare function addSettingEdit(declaration: SyntaxNode, setting: string): TextEdit | undefined;
|
|
14
|
+
export declare function updateSettingEdit(declaration: SyntaxNode, settingName: string, value: string | null | undefined, source: string): TextEdit | undefined;
|
|
15
|
+
export declare function removeSettingEdit(declaration: SyntaxNode, settingName: string, source: string): TextEdit | undefined;
|
|
16
|
+
export declare function findBodySetting(declaration: ElementDeclarationNode, settingName: string): ElementDeclarationNode | undefined;
|
|
@@ -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;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -4,15 +4,18 @@ export { Filepath } from './core/types/filepath';
|
|
|
4
4
|
export { UNHANDLED, type Unhandled, } from './core/types/module';
|
|
5
5
|
export { ElementKind } from './core/types/keywords';
|
|
6
6
|
export { type NodeSymbol, SymbolKind, } from './core/types/symbol';
|
|
7
|
+
export { MetadataKind } from './core/types/symbol/metadata';
|
|
7
8
|
export * from './core/global_modules/records/utils';
|
|
8
9
|
export * from './core/types/nodes';
|
|
9
10
|
export { SyntaxToken, SyntaxTokenKind, isTriviaToken, isOp, isOpToken, } from './core/types/tokens';
|
|
10
11
|
export { CompileError, CompileErrorCode, } from './core/types/errors';
|
|
11
12
|
export type { Position, } from './core/types';
|
|
12
|
-
export { ScopeKind, splitQualifiedIdentifier, unescapeString, escapeString, formatRecordValue, isValidIdentifier, addDoubleQuoteIfNeeded, } from './compiler/index';
|
|
13
|
+
export { ScopeKind, splitQualifiedIdentifier, unescapeString, escapeString, formatRecordValue, isValidIdentifier, addDoubleQuoteIfNeeded, normalizeQualifiedName, } from './compiler/index';
|
|
13
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';
|
|
14
15
|
export type { DiagramViewSyncOperation, DiagramViewBlock, TextEdit, } from './compiler/queries/transform';
|
|
16
|
+
export { findDiagramViewBlocks, findDepBlocks } from './compiler/queries/transform';
|
|
15
17
|
export type { DepSyncOperation, DepSyncEdge, DepEndpointRef, DepBlock, } from './compiler/queries/transform';
|
|
18
|
+
export type { ElementIdentifier, SchemaIdentifier, TableIdentifier, ColumnIdentifier, EnumIdentifier, EndpointRef, RefIdentifier, DepIdentifier, NoteIdentifier, TableGroupIdentifier, } from './compiler/queries/transform';
|
|
16
19
|
export { dbmlLanguageConfig, dbmlMonarchTokensProvider, } from './services/monarch';
|
|
17
20
|
export * from './compiler/projectLayout/layout';
|
|
18
21
|
export { Compiler };
|
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.
|
|
4
|
+
"version": "9.0.0-alpha.21",
|
|
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": "
|
|
53
|
+
"gitHead": "a615886aca6945409c3e3188e8058f7eb9096e66"
|
|
54
54
|
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Filepath } from '../../../core/types/filepath';
|
|
2
|
-
import { NodeSymbol } from '../../../core/types/symbol';
|
|
3
|
-
import { default as Compiler } from '../../index';
|
|
4
|
-
export type TableNameInput = string | {
|
|
5
|
-
schema?: string;
|
|
6
|
-
table: string;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Normalizes a table name input to { schema, table } format.
|
|
10
|
-
* Properly handles quoted identifiers with dots inside.
|
|
11
|
-
*/
|
|
12
|
-
export declare function normalizeTableName(input: TableNameInput): {
|
|
13
|
-
schema: string;
|
|
14
|
-
table: string;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Looks up a table symbol by matching its full qualified name.
|
|
18
|
-
*/
|
|
19
|
-
export declare function lookupTableSymbol(compiler: Compiler, filepath: Filepath, schema: string, table: string): NodeSymbol | null;
|
|
20
|
-
/**
|
|
21
|
-
* Removes surrounding double quotes from a string if present.
|
|
22
|
-
*/
|
|
23
|
-
export declare function stripQuotes(str: string): string;
|