@dbml/parse 8.0.0-alpha.0 → 8.0.0-alpha.11

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 (30) hide show
  1. package/dist/dbml-parse.js +22 -26
  2. package/dist/dbml-parse.mjs +499 -340
  3. package/dist/src/compiler/index.d.ts +12 -8
  4. package/dist/src/compiler/projectLayout/layout.d.ts +2 -6
  5. package/dist/src/compiler/queries/container/index.d.ts +5 -5
  6. package/dist/src/compiler/queries/files/reachableFiles.d.ts +1 -0
  7. package/dist/src/compiler/queries/files/usableMembers.d.ts +5 -3
  8. package/dist/src/compiler/queries/pipeline/index.d.ts +2 -2
  9. package/dist/src/compiler/queries/resolutionIndex.d.ts +2 -0
  10. package/dist/src/compiler/queries/transform/index.d.ts +3 -3
  11. package/dist/src/compiler/queries/transform/renameTable.d.ts +4 -6
  12. package/dist/src/compiler/queries/transform/syncDiagramView.d.ts +1 -1
  13. package/dist/src/core/global_modules/records/utils/data/values.d.ts +1 -1
  14. package/dist/src/core/global_modules/records/utils/index.d.ts +1 -0
  15. package/dist/src/core/local_modules/types.d.ts +1 -1
  16. package/dist/src/core/parser/parser.d.ts +2 -0
  17. package/dist/src/core/types/internable.d.ts +0 -12
  18. package/dist/src/core/types/module.d.ts +2 -1
  19. package/dist/src/core/types/symbol/index.d.ts +1 -1
  20. package/dist/src/index.d.ts +4 -4
  21. package/dist/src/services/index.d.ts +2 -2
  22. package/dist/src/services/monarch.d.ts +1 -1
  23. package/dist/src/services/suggestions/utils/useMerger.d.ts +2 -1
  24. package/dist/src/services/types.d.ts +1 -1
  25. package/package.json +4 -3
  26. /package/dist/src/core/global_modules/{program → records}/utils/constraints/fk.d.ts +0 -0
  27. /package/dist/src/core/global_modules/{program → records}/utils/constraints/helper.d.ts +0 -0
  28. /package/dist/src/core/global_modules/{program → records}/utils/constraints/index.d.ts +0 -0
  29. /package/dist/src/core/global_modules/{program → records}/utils/constraints/pk.d.ts +0 -0
  30. /package/dist/src/core/global_modules/{program → records}/utils/constraints/unique.d.ts +0 -0
@@ -5,17 +5,20 @@ import { DBMLCompletionItemProvider, DBMLDefinitionProvider, DBMLDiagnosticsProv
5
5
  import { DbmlProjectLayout } from './projectLayout';
6
6
  import { DiagramViewBlock, findDiagramViewBlocks } from './queries/transform';
7
7
  import { addDoubleQuoteIfNeeded, escapeString, formatRecordValue, isValidIdentifier, splitQualifiedIdentifier, unescapeString } from './queries/utils';
8
- export { ScopeKind, } from './types';
9
- export type { DiagramViewBlock, TableNameInput, TextEdit, } from './queries/transform';
8
+ export { ScopeKind } from './types';
9
+ export type { DiagramViewBlock, TableNameInput, TextEdit } from './queries/transform';
10
10
  export { addDoubleQuoteIfNeeded, escapeString, formatRecordValue, isValidIdentifier, splitQualifiedIdentifier, unescapeString, findDiagramViewBlocks, };
11
11
  export default class Compiler {
12
12
  readonly nodeIdGenerator: SyntaxNodeIdGenerator;
13
13
  readonly symbolIdGenerator: NodeSymbolIdGenerator;
14
14
  readonly symbolFactory: SymbolFactory;
15
15
  layout: DbmlProjectLayout;
16
- setSource(filepath: Filepath, source: string): void;
17
- clearSource(): void;
18
- deleteSource(filepath: Filepath): void;
16
+ constructor(layout?: DbmlProjectLayout);
17
+ getSource(filepath: Filepath): string | undefined;
18
+ private sourceSnapshot;
19
+ private cleanStaleLocalCache;
20
+ private entrypointsSnapshot;
21
+ private cleanStaleGlobalCache;
19
22
  private globalCache;
20
23
  private globalQuery;
21
24
  private localCache;
@@ -38,16 +41,17 @@ export default class Compiler {
38
41
  nodeSymbol: (node: SyntaxNode) => import('../core/types/report').default<import('../core/types/symbol').NodeSymbol> | import('../core/types/report').default<typeof import('..').UNHANDLED>;
39
42
  nodeMetadata: (node: SyntaxNode) => import('../core/types/report').default<typeof import('..').UNHANDLED> | import('../core/types/report').default<import('../core/types/symbol').NodeMetadata>;
40
43
  symbolMembers: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/report').default<typeof import('..').UNHANDLED> | import('../core/types/report').default<import('../core/types/symbol').NodeSymbol[]>;
41
- lookupMembers: (symbolOrNode: SyntaxNode | import('../core/types/symbol').NodeSymbol, targetKinds: import('../core/types/symbol').SymbolKind | import('../core/types/symbol').SymbolKind[], targetName: string) => import('../core/types/symbol').NodeSymbol | undefined;
44
+ lookupMembers: (symbolOrNode: import('../core/types/symbol').NodeSymbol | SyntaxNode, targetKinds: import('../core/types/symbol').SymbolKind | import('../core/types/symbol').SymbolKind[], targetName: string) => import('../core/types/symbol').NodeSymbol | undefined;
42
45
  nodeReferee: (node: SyntaxNode) => import('../core/types/report').default<typeof import('..').UNHANDLED> | import('../core/types/report').default<import('../core/types/symbol').NodeSymbol | undefined>;
43
46
  resolutionIndex: () => import('./queries/resolutionIndex').ResolutionIndex;
44
47
  symbolReferences: (symbol: import('../core/types/symbol').NodeSymbol) => SyntaxNode[];
48
+ symbolParent: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/symbol').NodeSymbol[];
45
49
  symbolMetadata: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/symbol').NodeMetadata[];
46
50
  symbolAliases: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/report').default<import('../core/types/symbol').AliasSymbol[]>;
47
51
  symbolUses: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/report').default<import('../core/types/symbol').UseSymbol[]>;
48
52
  fileDependencies: (filepath: Filepath) => Filepath[];
49
53
  reachableFiles: (entry?: Filepath | undefined) => Filepath[];
50
- usableMembers: (symbolOrFilepath: Filepath | import('../core/types/symbol').SchemaSymbol) => import('../core/types/report').default<{
54
+ usableMembers: (symbolOrFilepath: Filepath | import('../core/types/symbol').ProgramSymbol | import('../core/types/symbol').SchemaSymbol) => import('../core/types/report').default<{
51
55
  nonSchemaMembers: import('../core/types/symbol').NodeSymbol[];
52
56
  schemaMembers: import('../core/types/symbol').SchemaSymbol[];
53
57
  reuses: {
@@ -66,7 +70,7 @@ export default class Compiler {
66
70
  };
67
71
  }>;
68
72
  nodeAtPosition: (filepath: Filepath, offset: number) => SyntaxNode | import('..').SyntaxToken | undefined;
69
- renameTable: (filepath: Filepath, oldName: import('.').TableNameInput, newName: import('.').TableNameInput) => DbmlProjectLayout;
73
+ renameTable: (filepath: Filepath, oldName: import('.').TableNameInput, newName: import('.').TableNameInput) => Map<string, string>;
70
74
  syncDiagramView: (filepath: Filepath, operations: import('..').DiagramViewSyncOperation[], blocks?: DiagramViewBlock[] | undefined) => {
71
75
  newDbml: string;
72
76
  edits: import('.').TextEdit[];
@@ -1,15 +1,11 @@
1
1
  import { Filepath } from '../../core/types/filepath';
2
2
  export interface DbmlProjectLayout {
3
- setSource(filePath: Filepath, content: string): void;
4
3
  getSource(filePath: Filepath): string | undefined;
5
- deleteSource(filePath: Filepath): void;
6
- clearSource(): void;
7
4
  exists(filePath: Filepath): boolean;
8
5
  isFile(filePath: Filepath): boolean;
9
6
  isDirectory(filePath: Filepath): boolean;
10
7
  listDirectory(dirPath?: Filepath): Filepath[];
11
- getEntryPoints(): Filepath[];
12
- clone(): DbmlProjectLayout;
8
+ getEntrypoints(): Filepath[];
13
9
  }
14
10
  export declare class MemoryProjectLayout implements DbmlProjectLayout {
15
11
  private files;
@@ -22,6 +18,6 @@ export declare class MemoryProjectLayout implements DbmlProjectLayout {
22
18
  isFile(filePath: Filepath): boolean;
23
19
  isDirectory(filePath: Filepath): boolean;
24
20
  listDirectory(dirPath?: Filepath): Filepath[];
25
- getEntryPoints(): Filepath[];
21
+ getEntrypoints(): Filepath[];
26
22
  clone(): MemoryProjectLayout;
27
23
  }
@@ -1,5 +1,5 @@
1
- export { containerStack, } from './stack';
2
- export { containerToken, } from './token';
3
- export { containerElement, } from './element';
4
- export { containerScope, } from './scope';
5
- export { containerScopeKind, } from './scopeKind';
1
+ export { containerStack } from './stack';
2
+ export { containerToken } from './token';
3
+ export { containerElement } from './element';
4
+ export { containerScope } from './scope';
5
+ export { containerScopeKind } from './scopeKind';
@@ -1,3 +1,4 @@
1
1
  import { default as Compiler } from '../../index';
2
2
  import { Filepath } from '../../../core/types/filepath';
3
+ export declare function walkDependencies(compiler: Compiler, roots: Filepath[]): Filepath[];
3
4
  export declare function reachableFiles(this: Compiler, entry?: Filepath): Filepath[];
@@ -2,8 +2,8 @@ import { default as Compiler } from '../..';
2
2
  import { Filepath } from '../../../core/types/filepath';
3
3
  import { ElementDeclarationNode, UseSpecifierNode, WildcardNode } from '../../../core/types/nodes';
4
4
  import { default as Report } from '../../../core/types/report';
5
- import { NodeSymbol, SchemaSymbol } from '../../../core/types/symbol';
6
- export declare function usableMembers(this: Compiler, symbolOrFilepath: SchemaSymbol | Filepath): Report<{
5
+ import { NodeSymbol, SchemaSymbol, ProgramSymbol } from '../../../core/types/symbol';
6
+ type UsableResult = {
7
7
  nonSchemaMembers: NodeSymbol[];
8
8
  schemaMembers: SchemaSymbol[];
9
9
  reuses: {
@@ -20,7 +20,8 @@ export declare function usableMembers(this: Compiler, symbolOrFilepath: SchemaSy
20
20
  node: WildcardNode;
21
21
  }[];
22
22
  };
23
- }>;
23
+ };
24
+ export declare function usableMembers(this: Compiler, symbolOrFilepath: SchemaSymbol | ProgramSymbol | Filepath): Report<UsableResult>;
24
25
  export type SchemaMembership = {
25
26
  kind: 'direct';
26
27
  } | {
@@ -30,3 +31,4 @@ export type SchemaMembership = {
30
31
  kind: 'none';
31
32
  };
32
33
  export declare function schemaMembership(compiler: Compiler, schema: SchemaSymbol, element: ElementDeclarationNode | UseSpecifierNode): SchemaMembership;
34
+ export {};
@@ -1,2 +1,2 @@
1
- export { parseFile, } from './parse';
2
- export { interpretFile, } from './interpret';
1
+ export { parseFile } from './parse';
2
+ export { interpretFile } from './interpret';
@@ -5,7 +5,9 @@ import { default as Compiler } from '../index';
5
5
  export interface ResolutionIndex {
6
6
  references: Map<InternedNodeSymbol, SyntaxNode[]>;
7
7
  metadata: Map<InternedNodeSymbol, NodeMetadata[]>;
8
+ parents: Map<InternedNodeSymbol, NodeSymbol[]>;
8
9
  }
9
10
  export declare function resolutionIndex(this: Compiler): ResolutionIndex;
11
+ export declare function symbolParent(this: Compiler, symbol: NodeSymbol): NodeSymbol[];
10
12
  export declare function symbolReferences(this: Compiler, symbol: NodeSymbol): SyntaxNode[];
11
13
  export declare function symbolMetadata(this: Compiler, symbol: NodeSymbol): NodeMetadata[];
@@ -1,4 +1,4 @@
1
- export { renameTable, } from './renameTable';
1
+ export { renameTable } from './renameTable';
2
2
  export { syncDiagramView, findDiagramViewBlocks, type DiagramViewSyncOperation, type DiagramViewBlock, } from './syncDiagramView';
3
- export { applyTextEdits, type TextEdit, } from './applyTextEdits';
4
- export { type TableNameInput, } from './utils';
3
+ export { applyTextEdits, type TextEdit } from './applyTextEdits';
4
+ export { type TableNameInput } from './utils';
@@ -1,4 +1,3 @@
1
- import { DbmlProjectLayout } from '../../projectLayout/layout';
2
1
  import { Filepath } from '../../../core/types/filepath';
3
2
  import { default as Compiler } from '../../index';
4
3
  import { TableNameInput } from './utils';
@@ -20,9 +19,8 @@ import { TableNameInput } from './utils';
20
19
  * specifier source-name tokens, and refs that flow through unaliased
21
20
  * imports.
22
21
  *
23
- * Returns a fresh `DbmlProjectLayout` containing every file from the input
24
- * layout with the rename applied where appropriate. Files the rename did not
25
- * touch are returned with byte-identical source. A lookup miss or name
26
- * collision still produces a fresh-copy layout (caller can always swap).
22
+ * Returns a map of absolute file paths to new source content, containing
23
+ * only the files that were actually changed by the rename. An empty map
24
+ * indicates a no-op (lookup miss, name collision, or alias rename attempt).
27
25
  */
28
- export declare function renameTable(this: Compiler, filepath: Filepath, oldName: TableNameInput, newName: TableNameInput): DbmlProjectLayout;
26
+ export declare function renameTable(this: Compiler, filepath: Filepath, oldName: TableNameInput, newName: TableNameInput): Map<string, string>;
@@ -29,7 +29,7 @@ export interface DiagramViewBlock {
29
29
  /**
30
30
  * Returns the start/end byte positions of every DiagramView block in `source`.
31
31
  *
32
- * Returns an empty array on any lex or parse error -- callers cannot
32
+ * Returns an empty array on any lex or parse error - callers cannot
33
33
  * distinguish "no DiagramView blocks present" from "malformed DBML" based on
34
34
  * the return value alone. If you need to detect malformed input, lex/parse
35
35
  * the source separately and check for errors before calling this function.
@@ -1,5 +1,5 @@
1
1
  import { FunctionExpressionNode, SyntaxNode } from '../../../../types/nodes';
2
- export { extractNumericLiteral, } from '../../../../utils/expression';
2
+ export { extractNumericLiteral } from '../../../../utils/expression';
3
3
  export declare function isNullish(value: SyntaxNode): boolean;
4
4
  export declare function isEmptyStringLiteral(value: SyntaxNode): boolean;
5
5
  export declare function isFunctionExpression(value: SyntaxNode): value is FunctionExpressionNode;
@@ -1 +1,2 @@
1
1
  export * from './data';
2
+ export * from './constraints';
@@ -3,7 +3,7 @@ import { Module, PassThrough } from '../types/module';
3
3
  import { SyntaxNode } from '../types/nodes';
4
4
  import { default as Report } from '../types/report';
5
5
  import { Settings } from '../utils/validate';
6
- export type { Settings, };
6
+ export type { Settings };
7
7
  export interface LocalModule extends Module {
8
8
  validateNode?(compiler: Compiler, node: SyntaxNode): Report<void> | Report<PassThrough>;
9
9
  nodeFullname?(compiler: Compiler, node: SyntaxNode): Report<string[] | undefined> | Report<PassThrough>;
@@ -29,7 +29,9 @@ export default class Parser {
29
29
  private program;
30
30
  private useDeclaration;
31
31
  private useSpecifierList;
32
+ private synchronizeUseSpecifierList;
32
33
  private useSpecifier;
34
+ private synchronizeUseSpecifier;
33
35
  private synchronizeProgram;
34
36
  private elementDeclaration;
35
37
  private synchronizeElementDeclarationName;
@@ -6,15 +6,3 @@ export declare function intern<T extends Primitive, Id extends Primitive>(value:
6
6
  export declare function intern<Id extends Primitive>(value: Internable<Id>): Id;
7
7
  export declare function intern<T extends Primitive>(value: T): T;
8
8
  export declare function intern<T extends Primitive>(value: T[]): string;
9
- export declare class InternedMap<K extends Internable<P>, V, P extends Primitive = ReturnType<K['intern']>> {
10
- private readonly map;
11
- constructor();
12
- get(key: K): V | undefined;
13
- set(key: K, value: V): this;
14
- has(key: K): boolean;
15
- delete(key: K): boolean;
16
- get size(): number;
17
- entries(): IterableIterator<[P, V]>;
18
- [Symbol.iterator](): IterableIterator<[P, V]>;
19
- merge(other: InternedMap<K, V, P>): this;
20
- }
@@ -1,8 +1,9 @@
1
1
  import { default as Compiler } from '../../compiler';
2
+ import { default as Report } from './report';
2
3
  export declare const PASS_THROUGH: unique symbol;
3
4
  export type PassThrough = typeof PASS_THROUGH;
4
5
  export declare const UNHANDLED: unique symbol;
5
6
  export type Unhandled = typeof UNHANDLED;
6
7
  export interface Module {
7
- [index: string]: undefined | ((compiler: Compiler, ...args: any[]) => any);
8
+ [index: string]: undefined | ((compiler: Compiler, ...args: any[]) => Report<unknown> | Report<PassThrough>);
8
9
  }
@@ -1,4 +1,4 @@
1
1
  export * from './factory';
2
2
  export * from './symbols';
3
3
  export * from './metadata';
4
- export { default as SymbolFactory, } from './factory';
4
+ export { default as SymbolFactory } from './factory';
@@ -1,8 +1,8 @@
1
1
  import { default as Compiler } from './compiler/index';
2
- export { DEFAULT_ENTRY, } from './constants';
3
- export { Filepath, } from './core/types/filepath';
2
+ export { DEFAULT_ENTRY } from './constants';
3
+ export { Filepath } from './core/types/filepath';
4
4
  export { UNHANDLED, type Unhandled, } from './core/types/module';
5
- export { ElementKind, } from './core/types/keywords';
5
+ export { ElementKind } from './core/types/keywords';
6
6
  export { type NodeSymbol, SymbolKind, } from './core/types/symbol';
7
7
  export * from './core/global_modules/records/utils';
8
8
  export * from './core/types/nodes';
@@ -14,5 +14,5 @@ export { type Database, type MasterDatabase, type Table, type Note, type Column,
14
14
  export type { DiagramViewSyncOperation, DiagramViewBlock, TextEdit, } from './compiler/queries/transform';
15
15
  export { dbmlLanguageConfig, dbmlMonarchTokensProvider, } from './services/monarch';
16
16
  export * from './compiler/projectLayout/layout';
17
- export { Compiler, };
17
+ export { Compiler };
18
18
  export * from './services';
@@ -2,7 +2,7 @@ import { default as DBMLDefinitionProvider } from './definition/provider';
2
2
  import { default as DBMLDiagnosticsProvider } from './diagnostics/provider';
3
3
  import { default as DBMLReferencesProvider } from './references/provider';
4
4
  import { default as DBMLCompletionItemProvider } from './suggestions/provider';
5
- export type { Diagnostic, } from './diagnostics/provider';
5
+ export type { Diagnostic } from './diagnostics/provider';
6
6
  export * from './types';
7
7
  export { DBMLCompletionItemProvider, DBMLDefinitionProvider, DBMLReferencesProvider, DBMLDiagnosticsProvider, };
8
- export { dbmlMonarchTokensProvider, } from './monarch';
8
+ export { dbmlMonarchTokensProvider } from './monarch';
@@ -1,4 +1,4 @@
1
1
  import { LanguageConfiguration, MonarchLanguage } from './types';
2
2
  export declare const dbmlLanguageConfig: LanguageConfiguration;
3
3
  declare const dbmlMonarchTokensProvider: MonarchLanguage;
4
- export { dbmlMonarchTokensProvider, };
4
+ export { dbmlMonarchTokensProvider };
@@ -5,6 +5,7 @@ import { UseDeclarationNode } from '../../../core/types/nodes';
5
5
  export interface ParsedUseSpecifier {
6
6
  kind?: string;
7
7
  name: string;
8
+ alias?: string;
8
9
  }
9
10
  export interface ParsedUseStatement {
10
11
  startOffset: number;
@@ -20,7 +21,7 @@ export interface UseStatementMergeResult {
20
21
  endOffset: number;
21
22
  };
22
23
  }
23
- export declare function scanExistingUses(compiler: Compiler, filepath: Filepath, fileContent: string): ParsedUseStatement[];
24
+ export declare function scanExistingUses(compiler: Compiler, filepath: Filepath): ParsedUseStatement[];
24
25
  /** Merge a new symbol into the file's use statements.
25
26
  * If a use from sourceFile exists, add the symbol to it.
26
27
  * If not, create a new use statement at the top.
@@ -1,6 +1,6 @@
1
1
  import { CancellationToken as ICancellationToken, IDisposable, IPosition, IRange, editor, languages } from 'monaco-editor-core';
2
2
  import { URI as Uri } from 'monaco-editor-core/esm/vs/base/common/uri.js';
3
- export { Uri, };
3
+ export { Uri };
4
4
  export type LanguageConfiguration = languages.LanguageConfiguration;
5
5
  export type MonarchLanguage = languages.IMonarchLanguage;
6
6
  export type Position = IPosition;
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": "8.0.0-alpha.0",
4
+ "version": "8.0.0-alpha.11",
5
5
  "description": "DBML parser v2",
6
6
  "author": "Holistics <dev@holistics.io>",
7
7
  "license": "Apache-2.0",
@@ -40,10 +40,11 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "lodash-es": "^4.18.1",
43
- "luxon": "^3.7.2"
43
+ "luxon": "^3.7.2",
44
+ "pathe": "^2.0.3"
44
45
  },
45
46
  "engines": {
46
47
  "node": ">=18"
47
48
  },
48
- "gitHead": "4b99e7eab601b7d53e268d5d80048ee035614a79"
49
+ "gitHead": "976e0f27c85468fa8a0fbb2ded04862e86b05b89"
49
50
  }