@dbml/parse 8.3.1-custom-metadata.3 → 8.3.1-custom-metadata.4

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.
@@ -0,0 +1,29 @@
1
+ import { default as Compiler } from '../../../compiler/index';
2
+ import { Filepath, SettingName } from '../../types';
3
+ import { Column, Note, Table, TableGroup, TokenPosition } from '../../types/schemaJson';
4
+ import { ElementDeclarationNode, SyntaxNode } from '../../types/nodes';
5
+ import { NodeSymbol, SymbolKind, MetadataTargetKind } from '../../types/symbol';
6
+ export type MetadataTarget = Table | TableGroup | Note | Column;
7
+ /**
8
+ * Specs for builtin metadata (table's note, tablegroup's color, .etc) for different element types. Does 2 things:
9
+ * - `validate`: Validating if the metadata value is syntactically correct
10
+ * - `assign`: Write the metadata value to the element builtin props (e.g. write `table.note` instead of `table.metadata`)
11
+ */
12
+ interface MetadataField<T extends MetadataTarget> {
13
+ /** Check if the metadata value is syntactically correct */
14
+ isValidBuiltinFieldValue(node?: SyntaxNode): boolean;
15
+ message: string;
16
+ /** Write the metadata value to the element builtin props (e.g. write to `table.note`) */
17
+ assignBuiltinField(element: Partial<T>, value: string, token: TokenPosition): void;
18
+ }
19
+ export type MetadataFieldRegistry<T extends MetadataTarget, K extends SettingName = SettingName> = Record<K, MetadataField<T>>;
20
+ type NameWithSymbolKind = {
21
+ name: string;
22
+ symbolKind: SymbolKind;
23
+ };
24
+ /** @internal Exported for testing only. */
25
+ export declare function mapNamePartToSymbolKind(nameParts: string[], targetKind: MetadataTargetKind): NameWithSymbolKind[];
26
+ export declare function resolveMetadataTarget(compiler: Compiler, metadataNode: ElementDeclarationNode): NodeSymbol | undefined;
27
+ /** Merge every custom-metadata block, reachable from the current program, targeting element to it's `metadata` and other builtin (note/headercolor/...) fields */
28
+ export declare function attachCustomMetadata<T extends MetadataTarget>(compiler: Compiler, targetElement: Partial<T>, targetSymbol: NodeSymbol, fieldsRegistry: MetadataFieldRegistry<T, any>, filepath: Filepath): void;
29
+ export {};
@@ -1,8 +1,8 @@
1
1
  import { Note } from '../../types/schemaJson';
2
2
  import { default as Compiler } from '../../../compiler';
3
3
  import { SettingName, Filepath, NoteSymbol } from '../../types';
4
- import { MetadataFieldRegistry } from '../metadata/metadataField';
5
4
  import { default as Report } from '../../types/report';
5
+ import { MetadataFieldRegistry } from '../metadata/utils';
6
6
  export declare const NOTE_METADATA_FIELDS: MetadataFieldRegistry<Note, SettingName.Color>;
7
7
  export declare class StickyNoteInterpreter {
8
8
  private declarationNode;
@@ -3,9 +3,9 @@ import { SettingName } from '../../types/keywords';
3
3
  import { ElementDeclarationNode } from '../../types/nodes';
4
4
  import { default as Report } from '../../types/report';
5
5
  import { Column, Table } from '../../types/schemaJson';
6
- import { MetadataFieldRegistry } from '../metadata/metadataField';
7
6
  import { Filepath } from '../../types/filepath';
8
7
  import { TableSymbol } from '../../types/symbol/symbols';
8
+ import { MetadataFieldRegistry } from '../metadata/utils';
9
9
  export declare class TableInterpreter {
10
10
  private declarationNode;
11
11
  private compiler;
@@ -27,6 +27,11 @@ export declare class TableInterpreter {
27
27
  private interpretIndexes;
28
28
  private interpretChecks;
29
29
  }
30
+ /**
31
+ * Settings that are excluded from custom metadata for inline metadata for Column
32
+ * Different from what we extract from metadata block for Column because some settings value types are not supported yet, mostly boolean keys without values ([pk, not null])
33
+ * TODO: Catch these settings when we support more data types for custom metadata
34
+ */
30
35
  export declare const RECOGNIZED_COLUMN_SETTINGS: readonly SettingName[];
31
36
  export declare const TABLE_METADATA_FIELDS: MetadataFieldRegistry<Table, SettingName.Note | SettingName.HeaderColor>;
32
37
  export declare const COLUMN_METADATA_FIELDS: MetadataFieldRegistry<Column, SettingName.Note>;
@@ -1,8 +1,8 @@
1
1
  import { TableGroup } from '../../types/schemaJson';
2
2
  import { default as Compiler } from '../../../compiler';
3
3
  import { SettingName, Filepath, TableGroupSymbol } from '../../types';
4
- import { MetadataFieldRegistry } from '../metadata/metadataField';
5
4
  import { default as Report } from '../../types/report';
5
+ import { MetadataFieldRegistry } from '../metadata/utils';
6
6
  export declare const TABLEGROUP_METADATA_FIELDS: MetadataFieldRegistry<TableGroup, SettingName.Note | SettingName.Color>;
7
7
  export declare class TableGroupInterpreter {
8
8
  private 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.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")[];
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" | "Project" | "Records")[];
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.3.1-custom-metadata.3",
4
+ "version": "8.3.1-custom-metadata.4",
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": "be8c21d3525b0001b295695af7057e0e9cfae5d1"
53
+ "gitHead": "9b5601daf1b79ff7c96bc5766027447d1901c280"
54
54
  }
@@ -1,6 +0,0 @@
1
- import { default as Compiler } from '../../../compiler/index';
2
- import { Filepath } from '../../types/filepath';
3
- import { NodeSymbol } from '../../types/symbol';
4
- import { MetadataFieldRegistry, MetadataTarget } from './metadataField';
5
- /** Merge every custom-metadata block, reachable from the current program, targeting element to it's `metadata` and other builtin (note/headercolor/...) fields */
6
- export declare function attachCustomMetadata<T extends MetadataTarget>(compiler: Compiler, targetElement: Partial<T>, targetSymbol: NodeSymbol, fieldsRegistry: MetadataFieldRegistry<T, any>, filepath: Filepath): void;
@@ -1,4 +0,0 @@
1
- import { MetadataTargetKind } from '../../types/symbol';
2
- import { MetadataFieldRegistry, MetadataTarget } from './metadataField';
3
- export declare const METADATA_FIELDS_BY_KIND: Record<MetadataTargetKind, MetadataFieldRegistry<any, any>>;
4
- export type { MetadataFieldRegistry, MetadataTarget };
@@ -1,17 +0,0 @@
1
- import { SyntaxNode } from '../../types/nodes';
2
- import { Column, Note, Table, TableGroup, TokenPosition } from '../../types/schemaJson';
3
- import { SettingName } from '../../types';
4
- export type MetadataTarget = Table | TableGroup | Note | Column;
5
- /**
6
- * Specs for builtin metadata (table's note, tablegroup's color, .etc) for different element types. Does 2 things:
7
- * - `validate`: Validating if the metadata value is syntactically correct
8
- * - `assign`: Write the metadata value to the element builtin props (e.g. write `table.note` instead of `table.metadata`)
9
- */
10
- export interface MetadataField<T extends MetadataTarget> {
11
- /** Check if the metadata value is syntactically correct */
12
- isValidBuiltinFieldValue(node?: SyntaxNode): boolean;
13
- message: string;
14
- /** Write the metadata value to the element builtin props (e.g. write to `table.note`) */
15
- assignBuiltinField(element: Partial<T>, value: string, token: TokenPosition): void;
16
- }
17
- export type MetadataFieldRegistry<T extends MetadataTarget, K extends SettingName = SettingName> = Record<K, MetadataField<T>>;
@@ -1,11 +0,0 @@
1
- import { default as Compiler } from '../../../compiler/index';
2
- import { ElementDeclarationNode } from '../../types/nodes';
3
- import { NodeSymbol, SymbolKind, MetadataTargetKind } from '../../types/symbol';
4
- type NameWithSymbolKind = {
5
- name: string;
6
- symbolKind: SymbolKind;
7
- };
8
- /** @internal Exported for testing only. */
9
- export declare function mapNamePartToSymbolKind(nameParts: string[], targetKind: MetadataTargetKind): NameWithSymbolKind[];
10
- export declare function resolveMetadataTarget(compiler: Compiler, metadataNode: ElementDeclarationNode): NodeSymbol | undefined;
11
- export {};