@dbml/parse 9.0.0-optional-ref.0 → 9.0.0-optional-ref.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.
@@ -1,7 +1,7 @@
1
1
  import { Filepath } from '../core/types/filepath';
2
2
  import { SyntaxNode, SyntaxNodeIdGenerator } from '../core/types/nodes';
3
3
  import { NodeSymbolIdGenerator, SymbolFactory } from '../core/types/symbol';
4
- import { DBMLCompletionItemProvider, DBMLDefinitionProvider, DBMLDiagnosticsProvider, DBMLReferencesProvider } from '../services/index';
4
+ import { DBMLCodeActionProvider, DBMLCompletionItemProvider, DBMLDefinitionProvider, DBMLDiagnosticsProvider, DBMLReferencesProvider } from '../services/index';
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';
@@ -30,7 +30,7 @@ export default class Compiler {
30
30
  validateFile: (filepath: Filepath) => import('../core/types/report').default<void>;
31
31
  nodeFullname: (node: SyntaxNode) => import('../core/types/report').default<string[] | undefined> | import('../core/types/report').default<typeof import('..').UNHANDLED>;
32
32
  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<typeof import('..').UNHANDLED> | import('../core/types/report').default<import('../core/utils/validate').Settings>;
33
+ nodeSettings: (node: SyntaxNode) => import('../core/types/report').default<import('../core/utils/validate').Settings> | import('../core/types/report').default<typeof import('..').UNHANDLED>;
34
34
  canonicalName: (filepath: Filepath, symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/report').default<import('./queries/canonicalName').CanonicalName | undefined>;
35
35
  bindNode: (node: SyntaxNode) => import('../core/types/report').default<typeof import('..').UNHANDLED> | import('../core/types/report').default<void>;
36
36
  bindFile: (filepath: Filepath) => import('../core/types/report').default<void>;
@@ -77,6 +77,9 @@ export default class Compiler {
77
77
  newDbml: string;
78
78
  edits: import('.').TextEdit[];
79
79
  };
80
+ addSetting: (filepath: Filepath, declaration: SyntaxNode, setting: string) => string | undefined;
81
+ updateSetting: (filepath: Filepath, declaration: SyntaxNode, settingName: string, newValue: string) => string | undefined;
82
+ removeSetting: (filepath: Filepath, declaration: SyntaxNode, settingName: string) => string | undefined;
80
83
  findDiagramViewBlocks(filepath: Filepath): DiagramViewBlock[];
81
84
  readonly token: {
82
85
  invalidStream: (filepath: Filepath) => readonly import('..').SyntaxToken[];
@@ -113,5 +116,6 @@ export default class Compiler {
113
116
  referenceProvider: DBMLReferencesProvider;
114
117
  autocompletionProvider: DBMLCompletionItemProvider;
115
118
  diagnosticsProvider: DBMLDiagnosticsProvider;
119
+ codeActionProvider: DBMLCodeActionProvider;
116
120
  };
117
121
  }
@@ -0,0 +1,14 @@
1
+ import { SyntaxNode } from '../../../core/types/nodes';
2
+ import { Filepath } from '../../../core/types/filepath';
3
+ import { default as Compiler } from '../../index';
4
+ import { TextEdit } from './applyTextEdits';
5
+ /**
6
+ * Produces a TextEdit that adds a setting to a field/element declaration.
7
+ * If the declaration already has a settings block [...], inserts before the closing ].
8
+ * Otherwise, appends a new [setting] block.
9
+ */
10
+ export declare function addSettingEdit(declaration: SyntaxNode, setting: string): TextEdit | undefined;
11
+ /**
12
+ * Adds a setting to a field/element declaration and returns the updated source.
13
+ */
14
+ export declare function addSetting(this: Compiler, filepath: Filepath, declaration: SyntaxNode, setting: string): string | undefined;
@@ -1,4 +1,6 @@
1
1
  export { renameTable } from './renameTable';
2
2
  export { syncDiagramView, findDiagramViewBlocks, type DiagramViewSyncOperation, type DiagramViewBlock, } from './syncDiagramView';
3
3
  export { applyTextEdits, type TextEdit } from './applyTextEdits';
4
+ export { addSetting, addSettingEdit } from './addSetting';
5
+ export { updateSetting, updateSettingEdit, removeSetting, removeSettingEdit, } from './updateSetting';
4
6
  export { type TableNameInput } from './utils';
@@ -0,0 +1,8 @@
1
+ import { SyntaxNode } from '../../../core/types/nodes';
2
+ import { Filepath } from '../../../core/types/filepath';
3
+ import { default as Compiler } from '../../index';
4
+ import { TextEdit } from './applyTextEdits';
5
+ export declare function updateSettingEdit(declaration: SyntaxNode, settingName: string, newValue: string, source: string): TextEdit | undefined;
6
+ export declare function removeSettingEdit(declaration: SyntaxNode, settingName: string, source: string): TextEdit | undefined;
7
+ export declare function updateSetting(this: Compiler, filepath: Filepath, declaration: SyntaxNode, settingName: string, newValue: string): string | undefined;
8
+ export declare function removeSetting(this: Compiler, filepath: Filepath, declaration: SyntaxNode, settingName: string): string | undefined;
@@ -10,6 +10,7 @@ export default class ProgramInterpreter {
10
10
  private filepath;
11
11
  private errors;
12
12
  private warnings;
13
+ private hints;
13
14
  private db;
14
15
  constructor(compiler: Compiler, symbol: ProgramSymbol, filepath: Filepath);
15
16
  interpret(): Report<SchemaElement | SchemaElement[] | undefined>;
@@ -18,6 +19,7 @@ export default class ProgramInterpreter {
18
19
  private interpretAllMetadata;
19
20
  private interpretAllAliases;
20
21
  private validateRecords;
22
+ private validatePartialRefs;
21
23
  private collectPartialRefs;
22
24
  private pushElement;
23
25
  }
@@ -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;
@@ -0,0 +1,8 @@
1
+ import { default as Compiler } from '../../../compiler';
2
+ import { CompileInfo } from '../../types/errors';
3
+ import { RefMetadata, PartialRefMetadata } from '../../types/symbol/metadata';
4
+ export declare function validateCardinality(compiler: Compiler, meta: RefMetadata | PartialRefMetadata, side: 'left' | 'right', options?: {
5
+ allowOtherColFix?: boolean;
6
+ allowOwnColFix?: boolean;
7
+ }): CompileInfo[];
8
+ export declare function validatePartialRef(compiler: Compiler, meta: PartialRefMetadata): CompileInfo[];
@@ -13,5 +13,4 @@ export declare class RefInterpreter {
13
13
  private interpretName;
14
14
  private interpretBody;
15
15
  private validateRefConstraints;
16
- private validateCardinalityConstraints;
17
16
  }
@@ -115,12 +115,17 @@ export declare enum CompileErrorCode {
115
115
  CONFLICTING_SETTING = 5004,
116
116
  TABLE_REAPPEAR_IN_TABLEGROUP = 5005
117
117
  }
118
+ export interface RelatedLocation {
119
+ nodeOrToken: SyntaxNode | SyntaxToken;
120
+ message: string;
121
+ }
118
122
  export declare class CompileError extends Error {
119
123
  code: Readonly<CompileErrorCode>;
120
124
  diagnostic: Readonly<string>;
121
125
  nodeOrToken: Readonly<SyntaxNode | SyntaxToken>;
122
126
  start: Readonly<number>;
123
127
  end: Readonly<number>;
128
+ relatedLocations?: RelatedLocation[];
124
129
  constructor(code: number, message: string, nodeOrToken: SyntaxNode | SyntaxToken);
125
130
  toWarning(): CompileWarning;
126
131
  get filepath(): Filepath;
@@ -131,6 +136,26 @@ export declare class CompileWarning extends Error {
131
136
  nodeOrToken: Readonly<SyntaxNode | SyntaxToken>;
132
137
  start: Readonly<number>;
133
138
  end: Readonly<number>;
139
+ relatedLocations?: RelatedLocation[];
134
140
  constructor(code: number, message: string, nodeOrToken: SyntaxNode | SyntaxToken);
135
141
  get filepath(): Filepath;
136
142
  }
143
+ export interface QuickFix {
144
+ title: string;
145
+ filepath: Filepath;
146
+ edits: import('../../compiler/queries/transform/applyTextEdits').TextEdit[];
147
+ }
148
+ export declare class CompileInfo extends Error {
149
+ code: Readonly<CompileErrorCode>;
150
+ diagnostic: Readonly<string>;
151
+ nodeOrToken: Readonly<SyntaxNode | SyntaxToken>;
152
+ start: Readonly<number>;
153
+ end: Readonly<number>;
154
+ quickFixes?: QuickFix[];
155
+ relatedLocations?: RelatedLocation[];
156
+ constructor(code: number, message: string, nodeOrToken: SyntaxNode | SyntaxToken, options?: {
157
+ quickFixes?: QuickFix[];
158
+ relatedLocations?: RelatedLocation[];
159
+ });
160
+ get filepath(): Filepath;
161
+ }
@@ -13,4 +13,7 @@ export declare const CARDINALITY_SOME: RelationCardinality;
13
13
  export declare const CARDINALITY_MANY: RelationCardinality;
14
14
  export declare function getMultiplicities(op: string): [RelationCardinality, RelationCardinality] | undefined;
15
15
  export declare function getRelationshipOp(left: RelationCardinality, right: RelationCardinality): RelationshipOp;
16
+ export declare function makeCardinalityOptional(rel: RelationCardinality): RelationCardinality;
17
+ export declare function makeCardinalityRequired(rel: RelationCardinality): RelationCardinality;
18
+ export declare function makeCardinalityMany(rel: RelationCardinality): RelationCardinality;
16
19
  export {};
@@ -1,16 +1,18 @@
1
- import { CompileError, CompileWarning } from './errors';
1
+ import { CompileError, CompileWarning, CompileInfo } from './errors';
2
2
  export default class Report<T> {
3
3
  private value;
4
4
  private errors;
5
5
  private warnings?;
6
- static create<T>(value: T, errors?: CompileError[], warnings?: CompileWarning[]): Report<T>;
7
- constructor(value: T, errors?: CompileError[], warnings?: CompileWarning[]);
6
+ private hints?;
7
+ static create<T>(value: T, errors?: CompileError[], warnings?: CompileWarning[], hints?: CompileInfo[]): Report<T>;
8
+ constructor(value: T, errors?: CompileError[], warnings?: CompileWarning[], hints?: CompileInfo[]);
8
9
  filter<S extends symbol>(filteredValue: S): Report<undefined | Exclude<T, S>>;
9
10
  hasValue<S>(value: S): this is Report<S>;
10
11
  getFiltered<S extends symbol | undefined | null>(filteredValue: S): Exclude<T, S> | undefined;
11
12
  getValue(): T;
12
13
  getErrors(): CompileError[];
13
14
  getWarnings(): CompileWarning[];
15
+ getHints(): CompileInfo[];
14
16
  chainFiltered<S extends symbol | undefined | null, U>(fn: (_: Exclude<T, S>) => Report<U>, filteredValue: S): Report<U | undefined>;
15
17
  chain<U>(fn: (_: T) => Report<U>): Report<U>;
16
18
  mapFiltered<S extends symbol | undefined | null, U>(fn: (_: Exclude<T, S>) => U, filteredValue: S): Report<U | undefined>;
@@ -1,5 +1,6 @@
1
1
  import { default as Compiler } from '../../../compiler';
2
2
  import { AttributeNode, ElementDeclarationNode, SyntaxNode } from '../nodes';
3
+ import { SyntaxToken } from '../tokens';
3
4
  import { ColumnSymbol, NodeSymbol, TablePartialSymbol, TableSymbol } from '../symbol';
4
5
  import { Internable } from '../internable';
5
6
  import { RelationshipOp, RelationCardinality } from '../relation';
@@ -38,6 +39,7 @@ export declare class RefMetadata extends NodeMetadata {
38
39
  leftTable(compiler: Compiler): TableSymbol | undefined;
39
40
  rightTable(compiler: Compiler): TableSymbol | undefined;
40
41
  op(_compiler: Compiler): RelationshipOp | undefined;
42
+ opToken(): SyntaxToken | undefined;
41
43
  cardinalities(compiler: Compiler): [RelationCardinality, RelationCardinality] | undefined;
42
44
  leftCardinality(compiler: Compiler): {
43
45
  min: number;
@@ -61,6 +63,7 @@ export declare class PartialRefMetadata extends NodeMetadata {
61
63
  leftTablePartial(compiler: Compiler): TablePartialSymbol | undefined;
62
64
  rightTable(compiler: Compiler): TableSymbol | TablePartialSymbol | undefined;
63
65
  op(_compiler: Compiler): RelationshipOp | undefined;
66
+ opToken(): SyntaxToken | undefined;
64
67
  cardinalities(compiler: Compiler): [RelationCardinality, RelationCardinality] | undefined;
65
68
  leftCardinality(compiler: Compiler): {
66
69
  min: number;
@@ -147,9 +147,12 @@ export declare class ColumnSymbol extends NodeSymbol {
147
147
  }, id: NodeSymbolId, filepath: Filepath);
148
148
  get canBeImported(): boolean;
149
149
  get originalSymbol(): NodeSymbol;
150
+ qualifiedName(compiler: Compiler): string;
150
151
  pk(compiler: Compiler): boolean;
151
152
  unique(compiler: Compiler): boolean;
152
- nullable(compiler: Compiler): boolean | undefined;
153
+ nullable(compiler: Compiler): boolean;
154
+ isNotNullSet(compiler: Compiler): boolean | undefined;
155
+ isIncrementSet(compiler: Compiler): boolean;
153
156
  increment(compiler: Compiler): boolean;
154
157
  default(compiler: Compiler): {
155
158
  type: 'number' | 'string' | 'boolean' | 'expression';
@@ -0,0 +1,8 @@
1
+ import { default as Compiler } from '../../compiler';
2
+ import { CodeActionProvider, CodeActionList, CodeActionContext, TextModel, Range, CancellationToken } from '../types';
3
+ export default class DBMLCodeActionProvider implements CodeActionProvider {
4
+ private compiler;
5
+ constructor(compiler: Compiler);
6
+ provideCodeActions(model: TextModel, _range: Range, context: CodeActionContext, _token: CancellationToken): CodeActionList | undefined;
7
+ private quickFixToCodeAction;
8
+ }
@@ -1,8 +1,9 @@
1
1
  import { default as Compiler } from '../../compiler';
2
2
  import { Filepath } from '../../core/types/filepath';
3
+ import { RelatedLocation } from '../../core/types/errors';
3
4
  import { MarkerData } from '../types';
4
5
  export interface Diagnostic {
5
- type: 'error' | 'warning';
6
+ type: 'error' | 'warning' | 'hint';
6
7
  text: string;
7
8
  startRow: number;
8
9
  startColumn: number;
@@ -10,6 +11,7 @@ export interface Diagnostic {
10
11
  endColumn: number;
11
12
  code?: string | number;
12
13
  filepath: Filepath;
14
+ relatedLocations?: RelatedLocation[];
13
15
  }
14
16
  export default class DBMLDiagnosticsProvider {
15
17
  private compiler;
@@ -26,6 +28,10 @@ export default class DBMLDiagnosticsProvider {
26
28
  * Get only warnings from the current compilation
27
29
  */
28
30
  provideWarnings(filepath?: Filepath): Diagnostic[];
31
+ /**
32
+ * Get only hints from the current compilation
33
+ */
34
+ provideHints(filepath?: Filepath): Diagnostic[];
29
35
  /**
30
36
  * Convert Monaco markers format (for editor integration)
31
37
  */
@@ -1,8 +1,9 @@
1
+ import { default as DBMLCodeActionProvider } from './code_actions/provider';
1
2
  import { default as DBMLDefinitionProvider } from './definition/provider';
2
3
  import { default as DBMLDiagnosticsProvider } from './diagnostics/provider';
3
4
  import { default as DBMLReferencesProvider } from './references/provider';
4
5
  import { default as DBMLCompletionItemProvider } from './suggestions/provider';
5
6
  export type { Diagnostic } from './diagnostics/provider';
6
7
  export * from './types';
7
- export { DBMLCompletionItemProvider, DBMLDefinitionProvider, DBMLReferencesProvider, DBMLDiagnosticsProvider, };
8
+ export { DBMLCodeActionProvider, DBMLCompletionItemProvider, DBMLDefinitionProvider, DBMLReferencesProvider, DBMLDiagnosticsProvider, };
8
9
  export { dbmlMonarchTokensProvider } from './monarch';
@@ -62,8 +62,12 @@ export type ColorPresentation = languages.IColorPresentation;
62
62
  export type Color = languages.IColor;
63
63
  export type DefinitionProvider = languages.DefinitionProvider;
64
64
  export type Definition = languages.Definition;
65
- export type CodeActionList = languages.CodeActionList;
66
65
  export type SignatureHelpResult = languages.SignatureHelpResult;
66
+ export type CodeActionProvider = languages.CodeActionProvider;
67
+ export type CodeActionList = languages.CodeActionList;
68
+ export type CodeAction = languages.CodeAction;
69
+ export type CodeActionContext = languages.CodeActionContext;
70
+ export type WorkspaceEdit = languages.WorkspaceEdit;
67
71
  export type ReferenceProvider = languages.ReferenceProvider;
68
72
  export declare enum MarkerSeverity {
69
73
  Hint = 1,
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-optional-ref.0",
4
+ "version": "9.0.0-optional-ref.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": "01feeb4d524ff11d6cfaad16730a27c73e0d3b1f"
53
+ "gitHead": "3fc818b8e6033e2de577d012722d86a7509e4af3"
54
54
  }