@dbml/parse 9.0.0-alpha.1 → 9.0.0-alpha.2
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 +16 -13
- package/dist/dbml-parse.mjs +2331 -2096
- package/dist/src/compiler/index.d.ts +8 -3
- package/dist/src/compiler/queries/transform/index.d.ts +1 -0
- package/dist/src/compiler/queries/transform/syncDep.d.ts +90 -0
- package/dist/src/core/types/schemaJson.d.ts +1 -0
- package/dist/src/index.d.ts +1 -0
- package/package.json +2 -2
|
@@ -3,11 +3,11 @@ 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 { DiagramViewBlock, findDiagramViewBlocks } from './queries/transform';
|
|
6
|
+
import { DiagramViewBlock, DepBlock, findDiagramViewBlocks, findDepBlocks } from './queries/transform';
|
|
7
7
|
import { addDoubleQuoteIfNeeded, escapeString, formatRecordValue, isValidIdentifier, splitQualifiedIdentifier, unescapeString } from './queries/utils';
|
|
8
8
|
export { ScopeKind } from './types';
|
|
9
|
-
export type { DiagramViewBlock, TableNameInput, TextEdit } from './queries/transform';
|
|
10
|
-
export { addDoubleQuoteIfNeeded, escapeString, formatRecordValue, isValidIdentifier, splitQualifiedIdentifier, unescapeString, findDiagramViewBlocks, };
|
|
9
|
+
export type { DiagramViewBlock, DepBlock, TableNameInput, TextEdit } from './queries/transform';
|
|
10
|
+
export { addDoubleQuoteIfNeeded, escapeString, formatRecordValue, isValidIdentifier, splitQualifiedIdentifier, unescapeString, findDiagramViewBlocks, findDepBlocks, };
|
|
11
11
|
export default class Compiler {
|
|
12
12
|
layout: DbmlProjectLayout;
|
|
13
13
|
readonly nodeIdGenerator: SyntaxNodeIdGenerator;
|
|
@@ -78,6 +78,11 @@ export default class Compiler {
|
|
|
78
78
|
edits: import('.').TextEdit[];
|
|
79
79
|
};
|
|
80
80
|
findDiagramViewBlocks(filepath: Filepath): DiagramViewBlock[];
|
|
81
|
+
syncDep: (filepath: Filepath, operations: import('..').DepSyncOperation[], blocks?: DepBlock[] | undefined) => {
|
|
82
|
+
newDbml: string;
|
|
83
|
+
edits: import('.').TextEdit[];
|
|
84
|
+
};
|
|
85
|
+
findDepBlocks(filepath: Filepath): DepBlock[];
|
|
81
86
|
readonly token: {
|
|
82
87
|
invalidStream: (filepath: Filepath) => readonly import('..').SyntaxToken[];
|
|
83
88
|
flatStream: (filepath: Filepath) => readonly import('..').SyntaxToken[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { renameTable } from './renameTable';
|
|
2
2
|
export { syncDiagramView, findDiagramViewBlocks, type DiagramViewSyncOperation, type DiagramViewBlock, } from './syncDiagramView';
|
|
3
|
+
export { syncDep, findDepBlocks, generateDepBlock, type DepSyncOperation, type DepSyncEdge, type DepEndpointRef, type DepBlock, } from './syncDep';
|
|
3
4
|
export { applyTextEdits, type TextEdit } from './applyTextEdits';
|
|
4
5
|
export { type TableNameInput } from './utils';
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Filepath } from '../../../core/types/filepath';
|
|
2
|
+
import { default as Compiler } from '../../index';
|
|
3
|
+
import { TextEdit } from './applyTextEdits';
|
|
4
|
+
/** One endpoint of a dep edge. `fieldNames` is empty for a table-level edge. */
|
|
5
|
+
export interface DepEndpointRef {
|
|
6
|
+
schemaName?: string | null;
|
|
7
|
+
tableName: string;
|
|
8
|
+
fieldNames?: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface DepSyncEdge {
|
|
11
|
+
upstream: DepEndpointRef;
|
|
12
|
+
downstream: DepEndpointRef;
|
|
13
|
+
}
|
|
14
|
+
export interface DepSyncOperation {
|
|
15
|
+
operation: 'create' | 'update';
|
|
16
|
+
/** The edge that identifies the target block (table-level: empty fieldNames). */
|
|
17
|
+
edge: DepSyncEdge;
|
|
18
|
+
color?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A `color` setting found on a block.
|
|
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;
|
|
33
|
+
}
|
|
34
|
+
export interface DepBlock {
|
|
35
|
+
startIndex: number;
|
|
36
|
+
endIndex: number;
|
|
37
|
+
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
|
+
}
|
|
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
|
+
export interface InlineDep {
|
|
65
|
+
edge: DepSyncEdge;
|
|
66
|
+
stripStart: number;
|
|
67
|
+
stripEnd: number;
|
|
68
|
+
}
|
|
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
|
+
/**
|
|
79
|
+
* 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.
|
|
85
|
+
*/
|
|
86
|
+
export declare function syncDep(this: Compiler, filepath: Filepath, operations: DepSyncOperation[], blocks?: DepBlock[]): {
|
|
87
|
+
newDbml: string;
|
|
88
|
+
edits: TextEdit[];
|
|
89
|
+
};
|
|
90
|
+
export {};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export type { Position, } from './core/types';
|
|
|
12
12
|
export { ScopeKind, splitQualifiedIdentifier, unescapeString, escapeString, formatRecordValue, isValidIdentifier, addDoubleQuoteIfNeeded, } from './compiler/index';
|
|
13
13
|
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
14
|
export type { DiagramViewSyncOperation, DiagramViewBlock, TextEdit, } from './compiler/queries/transform';
|
|
15
|
+
export type { DepSyncOperation, DepSyncEdge, DepEndpointRef, DepBlock, } from './compiler/queries/transform';
|
|
15
16
|
export { dbmlLanguageConfig, dbmlMonarchTokensProvider, } from './services/monarch';
|
|
16
17
|
export * from './compiler/projectLayout/layout';
|
|
17
18
|
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.2",
|
|
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": "29e83a7d46ba317c1011a43021860348b8c829b5"
|
|
54
54
|
}
|