@dbml/parse 10.0.0-optional-ref.0 → 10.0.0

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 (51) hide show
  1. package/dist/dbml-parse.js +29 -19
  2. package/dist/dbml-parse.mjs +5951 -4730
  3. package/dist/src/compiler/index.d.ts +11 -7
  4. package/dist/src/compiler/queries/transform/index.d.ts +3 -1
  5. package/dist/src/compiler/queries/transform/renameTable.d.ts +2 -2
  6. package/dist/src/compiler/queries/transform/syncDep.d.ts +54 -0
  7. package/dist/src/compiler/queries/transform/types.d.ts +48 -0
  8. package/dist/src/compiler/queries/transform/updateElementSetting.d.ts +6 -0
  9. package/dist/src/compiler/queries/transform/utils/index.d.ts +26 -0
  10. package/dist/src/compiler/queries/transform/utils/ref.d.ts +15 -0
  11. package/dist/src/compiler/queries/utils.d.ts +6 -0
  12. package/dist/src/compiler/types.d.ts +9 -7
  13. package/dist/src/core/global_modules/dep/bind.d.ts +18 -0
  14. package/dist/src/core/global_modules/dep/index.d.ts +2 -0
  15. package/dist/src/core/global_modules/dep/interpret.d.ts +18 -0
  16. package/dist/src/core/global_modules/metadata/bind.d.ts +11 -0
  17. package/dist/src/core/global_modules/metadata/index.d.ts +2 -0
  18. package/dist/src/core/global_modules/metadata/interpret.d.ts +14 -0
  19. package/dist/src/core/global_modules/metadata/utils.d.ts +29 -0
  20. package/dist/src/core/global_modules/note/interpret.d.ts +3 -1
  21. package/dist/src/core/global_modules/program/utils/dep.d.ts +4 -0
  22. package/dist/src/core/global_modules/program/utils/external.d.ts +3 -0
  23. package/dist/src/core/global_modules/program/utils/index.d.ts +3 -0
  24. package/dist/src/core/global_modules/program/utils/records.d.ts +6 -0
  25. package/dist/src/core/global_modules/table/bind.d.ts +2 -0
  26. package/dist/src/core/global_modules/table/interpret.d.ts +12 -1
  27. package/dist/src/core/global_modules/tableGroup/interpret.d.ts +3 -1
  28. package/dist/src/core/global_modules/utils.d.ts +5 -1
  29. package/dist/src/core/local_modules/dep/index.d.ts +2 -0
  30. package/dist/src/core/local_modules/dep/validate.d.ts +19 -0
  31. package/dist/src/core/local_modules/metadata/index.d.ts +2 -0
  32. package/dist/src/core/local_modules/metadata/utils.d.ts +7 -0
  33. package/dist/src/core/local_modules/metadata/validate.d.ts +14 -0
  34. package/dist/src/core/types/errors.d.ts +62 -53
  35. package/dist/src/core/types/keywords.d.ts +4 -1
  36. package/dist/src/core/types/nodes.d.ts +14 -3
  37. package/dist/src/core/types/relation.d.ts +6 -2
  38. package/dist/src/core/types/schemaJson/types.d.ts +45 -1
  39. package/dist/src/core/types/symbol/metadata.d.ts +30 -11
  40. package/dist/src/core/types/symbol/symbols.d.ts +10 -1
  41. package/dist/src/core/utils/expression.d.ts +2 -1
  42. package/dist/src/core/utils/interpret.d.ts +12 -2
  43. package/dist/src/core/utils/note.d.ts +18 -0
  44. package/dist/src/core/utils/setting.d.ts +13 -14
  45. package/dist/src/core/utils/tokens.d.ts +3 -0
  46. package/dist/src/core/utils/validate.d.ts +16 -2
  47. package/dist/src/index.d.ts +7 -3
  48. package/dist/src/services/suggestions/provider.d.ts +19 -0
  49. package/package.json +4 -3
  50. package/dist/src/compiler/queries/transform/utils.d.ts +0 -23
  51. package/dist/src/core/global_modules/program/utils.d.ts +0 -3
@@ -57,64 +57,73 @@ export declare enum CompileErrorCode {
57
57
  INVALID_REF_FIELD = 3039,
58
58
  EMPTY_REF = 3040,
59
59
  REF_REDEFINED = 3041,
60
- INVALID_NOTE_CONTEXT = 3042,
61
- INVALID_NOTE = 3043,
62
- NOTE_REDEFINED = 3044,
63
- NOTE_CONTENT_REDEFINED = 3045,
64
- EMPTY_NOTE = 3046,
65
- UNKNOWN_NOTE_SETTING = 3047,
66
- DUPLICATE_NOTE_SETTING = 3048,
67
- INVALID_NOTE_SETTING_VALUE = 3049,
68
- INVALID_INDEXES_CONTEXT = 3050,
69
- INVALID_INDEXES_FIELD = 3051,
70
- INVALID_INDEX = 3052,
71
- UNKNOWN_INDEX_SETTING = 3053,
72
- DUPLICATE_INDEX_SETTING = 3054,
73
- UNEXPECTED_INDEX_SETTING_VALUE = 3055,
74
- INVALID_INDEX_SETTING_VALUE = 3056,
75
- INVALID_PROJECT_CONTEXT = 3057,
76
- PROJECT_REDEFINED = 3058,
77
- INVALID_PROJECT_FIELD = 3059,
78
- INVALID_CUSTOM_CONTEXT = 3060,
79
- INVALID_CUSTOM_ELEMENT_VALUE = 3061,
80
- INVALID_ELEMENT_IN_SIMPLE_BODY = 3062,
81
- INVALID_TABLE_PARTIAL_CONTEXT = 3063,
82
- INVALID_TABLE_PARTIAL_ELEMENT_NAME = 3064,
83
- INVALID_TABLE_PARTIAL_SETTING_VALUE = 3065,
84
- DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME = 3066,
85
- DUPLICATE_TABLE_PARTIAL_SETTING = 3067,
86
- INVALID_TABLE_PARTIAL_INJECTION = 3068,
87
- INVALID_TABLE_PARTIAL_INJECTION_OP = 3069,
88
- INVALID_TABLE_PARTIAL_INJECTION_NAME = 3070,
89
- DUPLICATE_TABLE_PARTIAL_INJECTION_NAME = 3071,
90
- UNKNOWN_TABLE_PARTIAL_SETTING = 3072,
91
- INVALID_TABLE_SETTING_VALUE = 3073,
92
- INVALID_CHECKS_CONTEXT = 3074,
93
- INVALID_CHECKS_FIELD = 3075,
94
- INVALID_CHECK = 3076,
95
- UNKNOWN_CHECK_SETTING = 3077,
96
- DUPLICATE_CHECK_SETTING = 3078,
97
- INVALID_CHECK_SETTING_VALUE = 3079,
98
- INVALID_RECORDS_CONTEXT = 3080,
99
- INVALID_RECORDS_NAME = 3081,
100
- INVALID_RECORDS_FIELD = 3082,
101
- DUPLICATE_COLUMN_REFERENCES_IN_RECORDS = 3083,
102
- DUPLICATE_RECORDS_FOR_TABLE = 3084,
103
- INVALID_USE_CONTEXT = 3085,
104
- INVALID_USE_SPECIFIER_KIND = 3086,
105
- INVALID_USE_SPECIFIER_NAME = 3087,
106
- INVALID_DIAGRAMVIEW_CONTEXT = 3088,
107
- DUPLICATE_DIAGRAMVIEW_NAME = 3089,
108
- INVALID_DIAGRAMVIEW_FIELD = 3090,
109
- DUPLICATE_DIAGRAMVIEW_FIELD = 3091,
60
+ INVALID_DEP_CONTEXT = 3042,
61
+ INVALID_DEP_FIELD = 3043,
62
+ INVALID_NOTE_CONTEXT = 3044,
63
+ INVALID_NOTE = 3045,
64
+ NOTE_REDEFINED = 3046,
65
+ NOTE_CONTENT_REDEFINED = 3047,
66
+ EMPTY_NOTE = 3048,
67
+ UNKNOWN_NOTE_SETTING = 3049,
68
+ DUPLICATE_NOTE_SETTING = 3050,
69
+ INVALID_NOTE_SETTING_VALUE = 3051,
70
+ INVALID_INDEXES_CONTEXT = 3052,
71
+ INVALID_INDEXES_FIELD = 3053,
72
+ INVALID_INDEX = 3054,
73
+ UNKNOWN_INDEX_SETTING = 3055,
74
+ DUPLICATE_INDEX_SETTING = 3056,
75
+ UNEXPECTED_INDEX_SETTING_VALUE = 3057,
76
+ INVALID_INDEX_SETTING_VALUE = 3058,
77
+ INVALID_PROJECT_CONTEXT = 3059,
78
+ PROJECT_REDEFINED = 3060,
79
+ INVALID_PROJECT_FIELD = 3061,
80
+ INVALID_CUSTOM_CONTEXT = 3062,
81
+ INVALID_CUSTOM_ELEMENT_VALUE = 3063,
82
+ INVALID_ELEMENT_IN_SIMPLE_BODY = 3064,
83
+ INVALID_TABLE_PARTIAL_CONTEXT = 3065,
84
+ INVALID_TABLE_PARTIAL_ELEMENT_NAME = 3066,
85
+ INVALID_TABLE_PARTIAL_SETTING_VALUE = 3067,
86
+ DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME = 3068,
87
+ DUPLICATE_TABLE_PARTIAL_SETTING = 3069,
88
+ INVALID_TABLE_PARTIAL_INJECTION = 3070,
89
+ INVALID_TABLE_PARTIAL_INJECTION_OP = 3071,
90
+ INVALID_TABLE_PARTIAL_INJECTION_NAME = 3072,
91
+ DUPLICATE_TABLE_PARTIAL_INJECTION_NAME = 3073,
92
+ UNKNOWN_TABLE_PARTIAL_SETTING = 3074,
93
+ INVALID_TABLE_SETTING_VALUE = 3075,
94
+ INVALID_CHECKS_CONTEXT = 3076,
95
+ INVALID_CHECKS_FIELD = 3077,
96
+ INVALID_CHECK = 3078,
97
+ UNKNOWN_CHECK_SETTING = 3079,
98
+ DUPLICATE_CHECK_SETTING = 3080,
99
+ INVALID_CHECK_SETTING_VALUE = 3081,
100
+ INVALID_RECORDS_CONTEXT = 3082,
101
+ INVALID_RECORDS_NAME = 3083,
102
+ INVALID_RECORDS_FIELD = 3084,
103
+ DUPLICATE_COLUMN_REFERENCES_IN_RECORDS = 3085,
104
+ DUPLICATE_RECORDS_FOR_TABLE = 3086,
105
+ INVALID_USE_CONTEXT = 3087,
106
+ INVALID_USE_SPECIFIER_KIND = 3088,
107
+ INVALID_USE_SPECIFIER_NAME = 3089,
108
+ INVALID_DIAGRAMVIEW_CONTEXT = 3090,
109
+ DUPLICATE_DIAGRAMVIEW_NAME = 3091,
110
+ INVALID_DIAGRAMVIEW_FIELD = 3092,
111
+ DUPLICATE_DIAGRAMVIEW_FIELD = 3093,
110
112
  BINDING_ERROR = 4000,
111
113
  NONEXISTENT_MODULE = 4001,
112
114
  UNSUPPORTED = 5000,
113
115
  CIRCULAR_REF = 5001,
114
116
  SAME_ENDPOINT = 5002,
115
- UNEQUAL_FIELDS_BINARY_REF = 5003,
116
- CONFLICTING_SETTING = 5004,
117
- TABLE_REAPPEAR_IN_TABLEGROUP = 5005
117
+ DEP_SELF_LOOP = 5003,
118
+ DEP_MIXED_DOWNSTREAM_TABLES = 5004,
119
+ DEP_DUPLICATE_DOWNSTREAM_TABLE = 5005,
120
+ DEP_MIXED_LEVEL = 5006,
121
+ UNEQUAL_FIELDS_BINARY_REF = 5007,
122
+ CONFLICTING_SETTING = 5008,
123
+ TABLE_REAPPEAR_IN_TABLEGROUP = 5009,
124
+ INVALID_METADATA_TARGET_KIND = 5010,
125
+ INVALID_METADATA_FIELD = 5011,
126
+ DUPLICATE_METADATA_FIELD = 5012
118
127
  }
119
128
  export interface RelatedLocation {
120
129
  nodeOrToken: SyntaxNode | SyntaxToken;
@@ -2,6 +2,7 @@ export declare enum ElementKind {
2
2
  Table = "table",
3
3
  Enum = "enum",
4
4
  Ref = "ref",
5
+ Dep = "dep",
5
6
  Note = "note",
6
7
  Project = "project",
7
8
  Indexes = "indexes",
@@ -13,7 +14,8 @@ export declare enum ElementKind {
13
14
  DiagramViewTables = "tables",
14
15
  DiagramViewNotes = "notes",
15
16
  DiagramViewTableGroups = "tablegroups",
16
- DiagramViewSchemas = "schemas"
17
+ DiagramViewSchemas = "schemas",
18
+ Metadata = "metadata"
17
19
  }
18
20
  export declare enum SettingName {
19
21
  Color = "color",
@@ -23,6 +25,7 @@ export declare enum SettingName {
23
25
  PrimaryKey = "primary key",
24
26
  Unique = "unique",
25
27
  Ref = "ref",
28
+ Dep = "dep",
26
29
  NotNull = "not null",
27
30
  Null = "null",
28
31
  Increment = "increment",
@@ -110,14 +110,16 @@ export declare class UseSpecifierListNode extends SyntaxNode {
110
110
  }
111
111
  export declare class ElementDeclarationNode extends SyntaxNode {
112
112
  type?: SyntaxToken;
113
+ targetKind?: SyntaxToken;
113
114
  name?: NormalExpressionNode;
114
115
  as?: SyntaxToken;
115
116
  alias?: NormalExpressionNode;
116
117
  attributeList?: ListExpressionNode;
117
118
  bodyColon?: SyntaxToken;
118
119
  body?: FunctionApplicationNode | BlockExpressionNode;
119
- constructor({ type, name, as, alias, attributeList, bodyColon, body, }: {
120
+ constructor({ type, targetKind, name, as, alias, attributeList, bodyColon, body, }: {
120
121
  type?: SyntaxToken;
122
+ targetKind?: SyntaxToken;
121
123
  name?: NormalExpressionNode;
122
124
  as?: SyntaxToken;
123
125
  alias?: NormalExpressionNode;
@@ -125,8 +127,17 @@ export declare class ElementDeclarationNode extends SyntaxNode {
125
127
  bodyColon?: SyntaxToken;
126
128
  body?: BlockExpressionNode | FunctionApplicationNode;
127
129
  }, id: SyntaxNodeId, filepath: Filepath);
128
- isKind(...kinds: ElementKind[]): boolean;
129
- getElementKind(): ElementKind | undefined;
130
+ isKind<T extends ElementKind>(...kinds: T[]): this is ElementDeclarationNode & {
131
+ type: {
132
+ value: T;
133
+ };
134
+ };
135
+ getElementKind<T extends ElementKind>(this: ElementDeclarationNode & {
136
+ type: {
137
+ value: T;
138
+ };
139
+ }): T;
140
+ getElementKind(this: ElementDeclarationNode): ElementKind | undefined;
130
141
  }
131
142
  export declare class IdentifierStreamNode extends SyntaxNode {
132
143
  identifiers: SyntaxToken[];
@@ -1,17 +1,21 @@
1
1
  type BaseRelationshipOp = '>' | '<' | '-' | '<>';
2
2
  export type RelationshipOp = `${'?' | ''}${BaseRelationshipOp}${'?' | ''}`;
3
3
  export type RelationCardinality = `${number}` | '*' | `${number}..${number | '*'}`;
4
- export declare function normalizeCardinality(c: RelationCardinality): RelationCardinality;
5
4
  export declare function parseCardinality(c: RelationCardinality): {
6
5
  min: number;
7
6
  max: number | '*';
8
7
  };
9
- export declare const RELATIONSHIP_OPS: ReadonlySet<RelationshipOp>;
10
8
  export declare const CARDINALITY_ONE: RelationCardinality;
11
9
  export declare const CARDINALITY_MAYBE: RelationCardinality;
12
10
  export declare const CARDINALITY_SOME: RelationCardinality;
13
11
  export declare const CARDINALITY_MANY: RelationCardinality;
12
+ export declare const RELATIONSHIP_OPS: ReadonlyMap<RelationshipOp, [RelationCardinality, RelationCardinality]>;
14
13
  export declare function getMultiplicities(op: string): [RelationCardinality, RelationCardinality] | undefined;
14
+ export declare function isEndpointOneSide(relation: RelationCardinality): boolean;
15
+ export declare function isEndpointManySide(relation: RelationCardinality): boolean;
16
+ export declare function isEndpointOptional(relation: RelationCardinality): boolean;
17
+ export declare function isEndpointRequired(relation: RelationCardinality): boolean;
18
+ export declare function makeRelationshipRequired(op: RelationshipOp): BaseRelationshipOp;
15
19
  export declare function getRelationshipOp(left: RelationCardinality, right: RelationCardinality): RelationshipOp;
16
20
  export declare function makeCardinalityOptional(rel: RelationCardinality): RelationCardinality;
17
21
  export declare function makeCardinalityRequired(rel: RelationCardinality): RelationCardinality;
@@ -2,6 +2,7 @@ import { NONE_COLOR } from '../../../constants';
2
2
  import { Filepath } from '../filepath';
3
3
  import { Position } from '../position';
4
4
  import { RelationshipOp, RelationCardinality } from '../relation';
5
+ export type CustomMetadata = Record<string, string>;
5
6
  export type Color = `#${string}` | typeof NONE_COLOR;
6
7
  export declare enum AliasKind {
7
8
  Table = "table"
@@ -59,6 +60,7 @@ export interface Database {
59
60
  tables: Table[];
60
61
  notes: Note[];
61
62
  refs: Ref[];
63
+ deps: Dep[];
62
64
  enums: Enum[];
63
65
  tableGroups: TableGroup[];
64
66
  aliases: Alias[];
@@ -86,12 +88,14 @@ export interface Table {
86
88
  value: string;
87
89
  token: TokenPosition;
88
90
  };
91
+ metadata?: CustomMetadata;
89
92
  }
90
93
  export interface Note {
91
94
  name: string;
92
95
  content: string;
93
96
  token: TokenPosition;
94
97
  color?: Color;
98
+ metadata?: CustomMetadata;
95
99
  }
96
100
  export interface ColumnType {
97
101
  schemaName: string | null;
@@ -111,6 +115,7 @@ export interface Column {
111
115
  type: ColumnType;
112
116
  token: TokenPosition;
113
117
  inline_refs: InlineRef[];
118
+ inline_deps: InlineDep[];
114
119
  checks: Check[];
115
120
  pk?: boolean;
116
121
  dbdefault?: {
@@ -124,6 +129,7 @@ export interface Column {
124
129
  value: string;
125
130
  token: TokenPosition;
126
131
  };
132
+ metadata?: CustomMetadata;
127
133
  }
128
134
  export interface Index {
129
135
  columns: {
@@ -171,6 +177,39 @@ export interface RefEndpoint {
171
177
  relation: RelationCardinality;
172
178
  token: TokenPosition;
173
179
  }
180
+ export interface Dep {
181
+ schemaName: string | null;
182
+ name: string | null;
183
+ edges: DepEdge[];
184
+ color?: Color;
185
+ note?: {
186
+ value: string;
187
+ token: TokenPosition;
188
+ };
189
+ metadata?: Record<string, string | number | boolean | null>;
190
+ token: TokenPosition;
191
+ }
192
+ export interface DepEdge {
193
+ upstream: DepEndpoint;
194
+ downstream: DepEndpoint;
195
+ token: TokenPosition;
196
+ }
197
+ export interface DepEndpoint {
198
+ schemaName: string | null;
199
+ tableName: string;
200
+ fieldNames: string[];
201
+ token: TokenPosition;
202
+ }
203
+ export declare const DEP_DOWNSTREAM: "->";
204
+ export declare const DEP_UPSTREAM: "<-";
205
+ export type DepDirection = typeof DEP_DOWNSTREAM | typeof DEP_UPSTREAM;
206
+ export interface InlineDep {
207
+ schemaName: string | null;
208
+ tableName: string;
209
+ fieldNames: string[];
210
+ direction: DepDirection;
211
+ token: TokenPosition;
212
+ }
174
213
  export interface Enum {
175
214
  name: string;
176
215
  schemaName: string | null;
@@ -195,6 +234,7 @@ export interface TableGroup {
195
234
  value: string;
196
235
  token: TokenPosition;
197
236
  };
237
+ metadata?: CustomMetadata;
198
238
  }
199
239
  export interface TableGroupField {
200
240
  name: string;
@@ -238,6 +278,10 @@ export interface TableRecord {
238
278
  values: RecordValue[][];
239
279
  token: TokenPosition;
240
280
  }
281
+ export type MetadataValues = Record<string, {
282
+ value: string;
283
+ token: TokenPosition;
284
+ }>;
241
285
  export type Project = Record<string, never> | {
242
286
  name: string | null;
243
287
  tables: Table[];
@@ -252,4 +296,4 @@ export type Project = Record<string, never> | {
252
296
  token: TokenPosition;
253
297
  [index: string & Omit<any, 'name' | 'tables' | 'refs' | 'enums' | 'tableGroups' | 'note' | 'tablePartials' | 'records'>]: string;
254
298
  };
255
- export type SchemaElement = Database | Project | Table | Note | Column | ColumnType | Index | Check | InlineRef | Ref | RefEndpoint | Enum | EnumField | TableGroup | TableGroupField | Alias | TablePartial | TablePartialInjection | TableRecord | RecordValue;
299
+ export type SchemaElement = Database | Project | Table | Note | Column | ColumnType | Index | Check | InlineRef | InlineDep | Ref | RefEndpoint | Dep | DepEdge | DepEndpoint | Enum | EnumField | TableGroup | TableGroupField | Alias | TablePartial | TablePartialInjection | TableRecord | RecordValue | MetadataValues;
@@ -1,16 +1,18 @@
1
1
  import { default as Compiler } from '../../../compiler';
2
- import { AttributeNode, ElementDeclarationNode, SyntaxNode } from '../nodes';
2
+ import { AttributeNode, ElementDeclarationNode, InfixExpressionNode, SyntaxNode } from '../nodes';
3
3
  import { SyntaxToken } from '../tokens';
4
- import { ColumnSymbol, NodeSymbol, TablePartialSymbol, TableSymbol } from '../symbol';
4
+ import { ColumnSymbol, NodeSymbol, ProgramSymbol, TablePartialSymbol, TableSymbol } from '../symbol';
5
5
  import { Internable } from '../internable';
6
6
  import { RelationshipOp, RelationCardinality } from '../relation';
7
7
  export declare enum MetadataKind {
8
8
  Ref = "ref",
9
+ Dep = "dep",
9
10
  PartialRef = "partial ref",
10
11
  TableChecks = "table checks",
11
12
  Indexes = "indexes",
12
13
  Records = "records",
13
- Project = "project"
14
+ Project = "project",
15
+ MetadataElement = "metadata element"
14
16
  }
15
17
  declare const __nodeMetadataBrand: unique symbol;
16
18
  export type NodeMetadataId = number & {
@@ -28,6 +30,11 @@ export declare abstract class NodeMetadata implements Internable<InternedNodeMet
28
30
  constructor(declaration: SyntaxNode);
29
31
  intern(): InternedNodeMetadata;
30
32
  abstract owners(compiler: Compiler): NodeSymbol[];
33
+ /** Get programs (source files) that can both
34
+ * - reach this metadata's declaration file and
35
+ * - see all the given target symbols in their nested schema.
36
+ */
37
+ resolveOwnerPrograms(compiler: Compiler, targets: NodeSymbol[]): ProgramSymbol[];
31
38
  }
32
39
  export declare class RefMetadata extends NodeMetadata {
33
40
  declaration: ElementDeclarationNode | AttributeNode;
@@ -54,6 +61,19 @@ export declare class RefMetadata extends NodeMetadata {
54
61
  rightToken(): SyntaxNode;
55
62
  owners(compiler: Compiler): NodeSymbol[];
56
63
  }
64
+ export declare class DepMetadata extends NodeMetadata {
65
+ declaration: ElementDeclarationNode | AttributeNode;
66
+ readonly kind = MetadataKind.Dep;
67
+ constructor(declaration: ElementDeclarationNode | AttributeNode);
68
+ container(compiler: Compiler): TableSymbol | undefined;
69
+ edgeExpressions(): InfixExpressionNode[];
70
+ upstreamColumns(compiler: Compiler): ColumnSymbol[][];
71
+ downstreamColumns(compiler: Compiler): ColumnSymbol[][];
72
+ upstreamTables(compiler: Compiler): (TableSymbol | undefined)[];
73
+ downstreamTables(compiler: Compiler): (TableSymbol | undefined)[];
74
+ private hostColumn;
75
+ owners(compiler: Compiler): NodeSymbol[];
76
+ }
57
77
  export declare class PartialRefMetadata extends NodeMetadata {
58
78
  readonly kind = MetadataKind.PartialRef;
59
79
  constructor(declaration: SyntaxNode);
@@ -65,14 +85,6 @@ export declare class PartialRefMetadata extends NodeMetadata {
65
85
  op(_compiler: Compiler): RelationshipOp | undefined;
66
86
  opToken(): SyntaxToken | undefined;
67
87
  cardinalities(compiler: Compiler): [RelationCardinality, RelationCardinality] | undefined;
68
- leftCardinality(compiler: Compiler): {
69
- min: number;
70
- max: number | '*';
71
- } | undefined;
72
- rightCardinality(compiler: Compiler): {
73
- min: number;
74
- max: number | '*';
75
- } | undefined;
76
88
  leftToken(): SyntaxNode;
77
89
  rightToken(): SyntaxNode;
78
90
  owners(compiler: Compiler): NodeSymbol[];
@@ -95,6 +107,13 @@ export declare class RecordsMetadata extends NodeMetadata {
95
107
  table(compiler: Compiler): TableSymbol | undefined;
96
108
  owners(compiler: Compiler): NodeSymbol[];
97
109
  }
110
+ export declare class MetadataElementMetadata extends NodeMetadata {
111
+ declaration: ElementDeclarationNode;
112
+ readonly kind = MetadataKind.MetadataElement;
113
+ constructor(declaration: ElementDeclarationNode);
114
+ target(compiler: Compiler): NodeSymbol | undefined;
115
+ owners(compiler: Compiler): NodeSymbol[];
116
+ }
98
117
  export declare class ProjectMetadata extends NodeMetadata {
99
118
  readonly kind = MetadataKind.Project;
100
119
  constructor(declaration: SyntaxNode);
@@ -24,6 +24,7 @@ export declare enum SymbolKind {
24
24
  DiagramViewTableGroup = "DiagramView tablegroup",
25
25
  DiagramViewNote = "DiagramView note",
26
26
  DiagramViewSchema = "DiagramView schema",
27
+ Metadata = "Metadata",
27
28
  Program = "Program"
28
29
  }
29
30
  export declare const ImportKind: {
@@ -35,6 +36,13 @@ export declare const ImportKind: {
35
36
  Schema: SymbolKind;
36
37
  };
37
38
  export type ImportKind = (typeof ImportKind)[keyof typeof ImportKind];
39
+ /** Allowed target element types for a Metadata element header */
40
+ export declare enum MetadataTargetKind {
41
+ Table = "Table",
42
+ Column = "Column",
43
+ TableGroup = "TableGroup",
44
+ Note = "Note"
45
+ }
38
46
  declare const __nodeSymbolBrand: unique symbol;
39
47
  export type NodeSymbolId = number & {
40
48
  readonly [__nodeSymbolBrand]: true;
@@ -147,11 +155,12 @@ export declare class ColumnSymbol extends NodeSymbol {
147
155
  }, id: NodeSymbolId, filepath: Filepath);
148
156
  get canBeImported(): boolean;
149
157
  get originalSymbol(): NodeSymbol;
150
- qualifiedName(compiler: Compiler): string;
158
+ qualifiedName(compiler: Compiler): string[];
151
159
  pk(compiler: Compiler): boolean;
152
160
  isUniqueSet(compiler: Compiler): boolean;
153
161
  unique(compiler: Compiler): boolean;
154
162
  nullable(compiler: Compiler): boolean;
163
+ private isInPkIndex;
155
164
  isNotNullSet(compiler: Compiler): boolean | undefined;
156
165
  isIncrementSet(compiler: Compiler): boolean;
157
166
  increment(compiler: Compiler): boolean;
@@ -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;
@@ -1,16 +1,26 @@
1
1
  import { default as Compiler } from '../../compiler';
2
- import { Color, ColumnType, TokenPosition } from '../types/schemaJson';
2
+ import { Color, ColumnType, CustomMetadata, TokenPosition } from '../types/schemaJson';
3
3
  import { SyntaxNode } from '../types/nodes';
4
4
  import { default as Report } from '../types/report';
5
+ import { Settings } from './validate';
6
+ import { SettingName } from '../types';
5
7
  export declare function getTokenPosition(node: SyntaxNode): TokenPosition;
6
8
  export declare function normalizeNote(content: string): string;
7
9
  export declare function extractElementName(nameNode: SyntaxNode): {
8
10
  schemaName: string[];
9
11
  name: string;
10
12
  };
11
- export declare function extractColor(node: unknown): Color | undefined;
13
+ export declare function extractColor(node?: SyntaxNode): Color | undefined;
12
14
  export declare function processDefaultValue(valueNode?: SyntaxNode): {
13
15
  type: 'number' | 'string' | 'boolean' | 'expression';
14
16
  value: string | number;
15
17
  } | undefined;
16
18
  export declare function processColumnType(compiler: Compiler, typeNode: SyntaxNode): Report<ColumnType>;
19
+ /**
20
+ * Extract inline custom metadata from an aggregated setting list,
21
+ * excluding keys that are natively attached to the element (headercolor and note in `table`, color in `tablegroup`, .etc).
22
+ *
23
+ * NOTE: This is used during interpret phase, so no need to validate values, just extract them
24
+ */
25
+ export declare function extractCustomInlineMetadata(settingMap: Settings, builtinSettings: readonly SettingName[]): CustomMetadata;
26
+ export declare function extractMetadataValue(node?: SyntaxNode): string | Color | 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;
@@ -1,17 +1,16 @@
1
- import { SyntaxNode } from '../types/nodes';
1
+ import { ListExpressionNode, AttributeNode, ElementDeclarationNode, SyntaxNode } from '../types/nodes';
2
2
  import { TextEdit } from '../../compiler/queries/transform/applyTextEdits';
3
- /**
4
- * Produces a TextEdit that adds a setting to a field/element declaration.
5
- * If the declaration already has a settings block [...], inserts before the closing ].
6
- * Otherwise, appends a new [setting] block.
7
- */
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;
8
13
  export declare function addSettingEdit(declaration: SyntaxNode, setting: string): TextEdit | undefined;
9
- /**
10
- * Produces a TextEdit that updates an existing setting's value in a declaration.
11
- */
12
- export declare function updateSettingEdit(declaration: SyntaxNode, settingName: string, newValue: string, source: string): TextEdit | undefined;
13
- /**
14
- * Produces a TextEdit that removes a setting from a declaration.
15
- * If it's the only setting, removes the entire settings block [...].
16
- */
14
+ export declare function updateSettingEdit(declaration: SyntaxNode, settingName: string, value: string | null | undefined, source: string): TextEdit | undefined;
17
15
  export declare function removeSettingEdit(declaration: SyntaxNode, settingName: string, source: string): TextEdit | undefined;
16
+ export declare function findBodySetting(declaration: ElementDeclarationNode, settingName: string): ElementDeclarationNode | undefined;
@@ -6,6 +6,9 @@ export declare function isAsKeyword(token?: SyntaxToken): token is SyntaxToken &
6
6
  export declare function isUseKeyword(token?: SyntaxToken): token is SyntaxToken & {
7
7
  kind: SyntaxTokenKind.IDENTIFIER;
8
8
  };
9
+ export declare function isMetadataKeyword(token?: SyntaxToken): token is SyntaxToken & {
10
+ kind: SyntaxTokenKind.IDENTIFIER;
11
+ };
9
12
  export declare function isFromKeyword(token?: SyntaxToken): token is SyntaxToken & {
10
13
  kind: SyntaxTokenKind.IDENTIFIER;
11
14
  };
@@ -24,7 +24,15 @@ 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 isValidColor(value?: SyntaxNode): boolean;
27
+ export declare function isDependencyOp(op?: string): boolean;
28
+ export declare function isValidHexColor(value?: SyntaxNode): value is PrimaryExpressionNode & {
29
+ expression: LiteralNode & {
30
+ literal: {
31
+ kind: SyntaxTokenKind.COLOR_LITERAL;
32
+ };
33
+ };
34
+ };
35
+ export declare function isValidColorOrNone(value?: SyntaxNode): boolean;
28
36
  export declare function isValidDefaultValue(value?: SyntaxNode): boolean;
29
37
  export type SignedNumberExpression = (PrimaryExpressionNode & {
30
38
  expression: LiteralNode & {
@@ -38,6 +46,7 @@ export type SignedNumberExpression = (PrimaryExpressionNode & {
38
46
  });
39
47
  export declare function isExpressionASignedNumberExpression(value?: SyntaxNode): value is SignedNumberExpression;
40
48
  export declare function isUnaryRelationship(value?: SyntaxNode): value is PrefixExpressionNode;
49
+ export declare function isUnaryDependency(value?: SyntaxNode): value is PrefixExpressionNode;
41
50
  export declare function isTupleOfVariables(value?: SyntaxNode): value is TupleExpressionNode & {
42
51
  elementList: (PrimaryExpressionNode & {
43
52
  expression: VariableNode;
@@ -45,6 +54,7 @@ export declare function isTupleOfVariables(value?: SyntaxNode): value is TupleEx
45
54
  };
46
55
  export declare function isValidColumnType(type: SyntaxNode): boolean;
47
56
  export type Settings = Record<SettingName | string, AttributeNode[]>;
57
+ export declare function isValidMetadataValue(value?: SyntaxNode): boolean;
48
58
  export declare function aggregateSettingList(settingList?: ListExpressionNode): Report<Settings>;
49
59
  export declare function isExpressionAQuotedString(value?: unknown): value is PrimaryExpressionNode & ({
50
60
  expression: VariableNode & {
@@ -84,7 +94,11 @@ type DotDelimitedIdentifier = PrimaryExpressionNode | (AccessExpression & {
84
94
  });
85
95
  export declare function isAccessExpression(node?: SyntaxNode): node is AccessExpression;
86
96
  export declare function isDotDelimitedIdentifier(node?: SyntaxNode): node is DotDelimitedIdentifier;
87
- export declare function isElementNode(node: SyntaxNode | undefined, kind: ElementKind): node is ElementDeclarationNode;
97
+ export declare function isElementNode<T extends ElementKind>(node: SyntaxNode | undefined, kind: T): node is ElementDeclarationNode & {
98
+ type: {
99
+ value: T;
100
+ };
101
+ };
88
102
  export declare function isUseDeclaration(node: SyntaxNode): node is UseDeclarationNode;
89
103
  export declare function isUseSpecifier(node: SyntaxNode, kind?: ImportKind): node is UseSpecifierNode;
90
104
  export declare function isWildcardSpecifier(node: SyntaxNode): node is WildcardNode;
@@ -4,15 +4,19 @@ 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 { 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 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
- export { type RelationCardinality, type RelationshipOp, getRelationshipOp, getMultiplicities, parseCardinality, makeCardinalityRequired, makeCardinalityOptional, CARDINALITY_ONE, CARDINALITY_MAYBE, CARDINALITY_SOME, CARDINALITY_MANY, } from './core/types/relation';
13
+ export { ScopeKind, splitQualifiedIdentifier, unescapeString, escapeString, formatRecordValue, isValidIdentifier, addDoubleQuoteIfNeeded, normalizeQualifiedName, } from './compiler/index';
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 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, type CustomMetadata, } from './core/types/schemaJson';
15
+ export { type RelationCardinality, type RelationshipOp, getRelationshipOp, getMultiplicities, parseCardinality, makeCardinalityRequired, makeCardinalityOptional, makeRelationshipRequired, isEndpointOneSide, isEndpointManySide, isEndpointOptional, isEndpointRequired, CARDINALITY_ONE, CARDINALITY_MAYBE, CARDINALITY_SOME, CARDINALITY_MANY, } from './core/types/relation';
15
16
  export type { DiagramViewSyncOperation, DiagramViewBlock, TextEdit, } from './compiler/queries/transform';
17
+ export { findDiagramViewBlocks, findDepBlocks } from './compiler/queries/transform';
18
+ export type { DepSyncOperation, DepSyncEdge, DepEndpointRef, DepBlock, } from './compiler/queries/transform';
19
+ export type { ElementIdentifier, SchemaIdentifier, TableIdentifier, ColumnIdentifier, EnumIdentifier, EndpointRef, RefIdentifier, DepIdentifier, NoteIdentifier, TableGroupIdentifier, } from './compiler/queries/transform';
16
20
  export { dbmlLanguageConfig, dbmlMonarchTokensProvider, } from './services/monarch';
17
21
  export * from './compiler/projectLayout/layout';
18
22
  export { Compiler };
@@ -1,5 +1,23 @@
1
1
  import { default as Compiler } from '../../compiler';
2
+ import { SettingName } from '../../core/types/keywords';
2
3
  import { CompletionItemProvider, CompletionList, Position, TextModel } from '../types';
4
+ export declare const COLUMN_TYPE_SUGGESTION_LABELS: readonly ["integer", "int", "tinyint", "smallint", "mediumint", "bigint", "bit", "bool", "binary", "varbinary", "logical", "char", "nchar", "varchar", "varchar2", "nvarchar", "nvarchar2", "binary_float", "binary_double", "float", "double", "decimal", "dec", "real", "money", "smallmoney", "enum", "tinyblob", "tinytext", "blob", "text", "mediumblob", "mediumtext", "longblob", "longtext", "ntext", "set", "inet6", "uuid", "image", "date", "time", "datetime", "datetime2", "timestamp", "year", "smalldatetime", "datetimeoffset", "XML", "sql_variant", "uniqueidentifier", "CURSOR", "BFILE", "CLOB", "NCLOB", "RAW"];
5
+ export declare const TABLE_SETTING_SUGGESTION_LABELS: readonly [SettingName.HeaderColor, SettingName.Note];
6
+ export declare const TABLE_SETTING_SUGGESTION_TEXT_INSERTS: string[];
7
+ export declare const COLUMN_SUGGESTION_LABELS: (SettingName.Note | SettingName.PK | SettingName.PrimaryKey | SettingName.Unique | SettingName.Ref | SettingName.Dep | SettingName.NotNull | SettingName.Null | SettingName.Increment | SettingName.Default | SettingName.Check)[];
8
+ export declare const COLUMN_SUGGESTION_TEXT_INSERTS: string[];
9
+ export declare const INDEX_SETTING_SUGGESTION_LABELS: (SettingName.Note | SettingName.PK | SettingName.Unique | SettingName.Name | SettingName.Type)[];
10
+ export declare const INDEX_SETTING_SUGGESTION_TEXT_INSERTS: string[];
11
+ export declare const REF_SETTING_SUGGESTION_LABELS: (SettingName.Color | SettingName.Update | SettingName.Delete | SettingName.Inactive)[];
12
+ export declare const REF_SETTING_SUGGESTION_TEXT_INSERTS: string[];
13
+ export declare const ENUM_SETTING_SUGGESTION_LABELS: readonly [SettingName.Note];
14
+ export declare const ENUM_SETTING_SUGGESTION_TEXT_INSERTS: string[];
15
+ export declare const CHECK_SETTING_SUGGESTION_LABELS: readonly [SettingName.Name];
16
+ export declare const CHECK_SETTING_SUGGESTION_TEXT_INSERTS: string[];
17
+ export declare const REF_ACTION_VALUE_SUGGESTIONS: readonly ["cascade", "set default", "set null", "restrict"];
18
+ export declare const INDEX_TYPE_VALUE_SUGGESTIONS: readonly ["btree", "hash"];
19
+ export declare const TABLE_BODY_SUGGESTION_LABELS: ("indexes" | "checks" | "Note" | "Records")[];
20
+ export declare const PROJECT_FIELD_SUGGESTION_LABELS: ("Table" | "Enum" | "TableGroup" | "TablePartial" | "Note" | "Ref" | "Dep")[];
3
21
  export interface DBMLCompletionItemProviderOptions {
4
22
  triggerCharacters?: string[];
5
23
  }
@@ -9,3 +27,4 @@ export default class DBMLCompletionItemProvider implements CompletionItemProvide
9
27
  constructor(compiler: Compiler, options?: DBMLCompletionItemProviderOptions);
10
28
  provideCompletionItems(model: TextModel, position: Position): CompletionList;
11
29
  }
30
+ export declare const TOP_LEVEL_SUGGESTION_LABELS: ("Table" | "Enum" | "TableGroup" | "TablePartial" | "Note" | "DiagramView" | "Metadata" | "Ref" | "Dep" | "Project" | "Records")[];