@dbml/core 6.4.0-alpha.0 → 6.5.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@dbml/core",
4
- "version": "6.4.0-alpha.0",
4
+ "version": "6.5.0",
5
5
  "description": "> TODO: description",
6
6
  "author": "Holistics <dev@holistics.io>",
7
7
  "license": "Apache-2.0",
@@ -46,7 +46,7 @@
46
46
  "lint:fix": "eslint --fix ."
47
47
  },
48
48
  "dependencies": {
49
- "@dbml/parse": "^6.4.0-alpha.0",
49
+ "@dbml/parse": "^6.5.0",
50
50
  "antlr4": "^4.13.1",
51
51
  "lodash": "^4.17.15",
52
52
  "lodash-es": "^4.17.15",
@@ -57,7 +57,7 @@
57
57
  "devDependencies": {
58
58
  "bluebird": "^3.5.5"
59
59
  },
60
- "gitHead": "ba26cc72483183193335e053d122c28d0aa13575",
60
+ "gitHead": "9ed15e01a00d4f58564ccdfb75f2f85bf5de5199",
61
61
  "engines": {
62
62
  "node": ">=16"
63
63
  }
@@ -0,0 +1,30 @@
1
+ import type { NormalizedModel } from '../model_structure/database';
2
+ import type { NormalizedTable } from '../model_structure/table';
3
+ import type { NormalizedTableGroup } from '../model_structure/tableGroup';
4
+
5
+ export interface DbmlExporterOptions {
6
+ /** When false, TableData (Records) blocks are omitted from the output. Defaults to true. */
7
+ includeRecords: boolean;
8
+ }
9
+
10
+ declare class DbmlExporter {
11
+ static hasWhiteSpace(str: string): boolean;
12
+ static hasSquareBracket(str: string): boolean;
13
+ static isExpression(str: string): boolean;
14
+ static escapeNote(str: string | null): string;
15
+ static exportEnums(enumIds: number[], model: NormalizedModel): string;
16
+ static getFieldLines(tableId: number, model: NormalizedModel): string[];
17
+ static getIndexLines(tableId: number, model: NormalizedModel): string[];
18
+ static getCheckLines(tableId: number, model: NormalizedModel): string[];
19
+ static getTableSettings(table: NormalizedTable): string;
20
+ static exportTables(tableIds: number[], model: NormalizedModel): string;
21
+ static buildFieldName(fieldIds: number[], model: NormalizedModel): string;
22
+ static exportRefs(refIds: number[], model: NormalizedModel): string;
23
+ static getTableGroupSettings(tableGroup: NormalizedTableGroup): string;
24
+ static exportTableGroups(tableGroupIds: number[], model: NormalizedModel): string;
25
+ static exportStickyNotes(model: NormalizedModel): string;
26
+ static exportRecords(model: NormalizedModel): string;
27
+ static export(model: NormalizedModel, options: DbmlExporterOptions): string;
28
+ }
29
+
30
+ export default DbmlExporter;
@@ -0,0 +1,13 @@
1
+ import type Database from '../model_structure/database';
2
+ import type { NormalizedModel } from '../model_structure/database';
3
+
4
+ export interface JsonExporterOptions {
5
+ /** When false, the model is exported via its `.export()` method before stringifying. Defaults to true. */
6
+ isNormalized: boolean;
7
+ }
8
+
9
+ declare class JsonExporter {
10
+ static export(model: Database | NormalizedModel, options: JsonExporterOptions): string;
11
+ }
12
+
13
+ export default JsonExporter;
@@ -1,15 +1,13 @@
1
- import Database, { NormalizedModel } from '../model_structure/database';
1
+ import type Database from '../model_structure/database';
2
+ import type { NormalizedModel } from '../model_structure/database';
3
+ import type { ExportFormat, ExportOptions } from './index';
2
4
 
3
- export declare type ExportFormatOption = 'dbml' | 'mysql' | 'postgres' | 'json' | 'mssql' | 'oracle';
4
- export interface ExportFlags {
5
- isNormalized?: boolean;
6
- includeRecords?: boolean;
7
- }
8
5
  declare class ModelExporter {
9
6
  /**
10
- * @deprecated Passing a boolean as the third argument is deprecated. Use `{ isNormalized: boolean }` instead.
7
+ * @deprecated Passing a boolean as the third argument is deprecated. Use `ExportOptions` instead.
11
8
  */
12
- static export(model: Database | NormalizedModel, format: ExportFormatOption, isNormalized: boolean): string;
13
- static export(model: Database | NormalizedModel, format: ExportFormatOption, flags?: ExportFlags): string;
9
+ static export(model: Database | NormalizedModel, format: ExportFormat, options: boolean): string;
10
+ static export(model: Database | NormalizedModel, format: ExportFormat, options?: ExportOptions): string;
14
11
  }
12
+
15
13
  export default ModelExporter;
@@ -1,7 +1,15 @@
1
- import { ExportFormatOption, ExportFlags } from './ModelExporter';
2
- import { RecordValueType } from '../model_structure/database';
1
+ import type { DbmlExporterOptions } from './DbmlExporter';
2
+ import type { JsonExporterOptions } from './JsonExporter';
3
+
4
+ export type ExportFormat = 'dbml' | 'mysql' | 'postgres' | 'json' | 'mssql' | 'oracle';
5
+
6
+ export type ExportOptions =
7
+ Partial<DbmlExporterOptions> &
8
+ Partial<JsonExporterOptions>;
9
+
10
+ declare function _export(str: string, format: ExportFormat, options: boolean): string;
11
+ declare function _export(str: string, format: ExportFormat, options?: ExportOptions): string;
3
12
 
4
- declare function _export(str: string, format: ExportFormatOption, flags?: ExportFlags): string;
5
13
  declare const _default: {
6
14
  export: typeof _export;
7
15
  };
@@ -1,11 +1,18 @@
1
- declare function _import(str: string, format: 'dbml' | 'mysql' | 'postgres' | 'json' | 'mssql' | 'postgresLegacy' | 'mssqlLegacy' | 'oracle'): string;
1
+ import type { DbmlExporterOptions } from '../export/DbmlExporter';
2
+
3
+ export type ImportFormat = 'dbml' | 'mysql' | 'postgres' | 'json' | 'mssql' | 'postgresLegacy' | 'mssqlLegacy' | 'schemarb' | 'snowflake' | 'oracle';
4
+
5
+ export type ImportOptions = Partial<DbmlExporterOptions>;
6
+
7
+ declare function _import(str: string, format: ImportFormat, options?: ImportOptions): string;
2
8
 
3
9
  /**
4
- * @param {any} schemaJson
10
+ * @param schemaJson
5
11
  * @description Type of schemaJson is `DatabaseSchema`.
6
12
  * The type definition of `DatabaseSchema` object can be found [here](https://github.com/holistics/dbml/blob/a4dcb110f1d79f5d95b0d3db4b919914439e039d/packages/dbml-connector/src/connectors/types.ts#L89)
7
13
  */
8
- declare function generateDbml(schemaJson: any): string;
14
+ declare function generateDbml(schemaJson: unknown): string;
15
+
9
16
  declare const _default: {
10
17
  import: typeof _import;
11
18
  generateDbml: typeof generateDbml;
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import ModelExporter, { ExportFormatOption } from './export/ModelExporter';
1
+ import ModelExporter from './export/ModelExporter';
2
2
  import Parser from './parse/Parser';
3
3
  import importer from './import';
4
4
  import exporter from './export';
@@ -10,9 +10,12 @@ export {
10
10
  importer,
11
11
  exporter,
12
12
  ModelExporter,
13
- ExportFormatOption,
14
13
  Parser,
15
14
  };
15
+ export type { ExportFormat, ExportOptions } from './export/index';
16
+ export type { DbmlExporterOptions } from './export/DbmlExporter';
17
+ export type { JsonExporterOptions } from './export/JsonExporter';
18
+ export type { ImportFormat, ImportOptions } from './import/index';
16
19
  export { CompilerDiagnostic, CompilerError as CompilerDiagnostics, EditorPosition, ErrorCode, WarningLevel } from './parse/error';
17
20
 
18
21
  export * from './model_structure';
@@ -4,7 +4,7 @@ import Field from './field';
4
4
  import Table from './table';
5
5
  import TablePartial from './tablePartial';
6
6
 
7
- interface RawCheck {
7
+ export interface RawCheck {
8
8
  token: Token;
9
9
  name: string;
10
10
  expression: string;
@@ -38,6 +38,7 @@ export interface RawTableRecord {
38
38
 
39
39
  export interface TableRecord extends RawTableRecord {
40
40
  id: number;
41
+ tableId?: number;
41
42
  }
42
43
 
43
44
  export type NormalizedRecord = TableRecord;
@@ -13,5 +13,5 @@ export default class DbState {
13
13
  fieldId: number;
14
14
  indexColumnId: number;
15
15
  tablePartialId: number;
16
- generateId(el: string): any;
16
+ generateId(el: string): number;
17
17
  }
@@ -4,7 +4,7 @@ import Element, { Token, RawNote } from './element';
4
4
  import EnumValue from './enumValue';
5
5
  import Field from './field';
6
6
  import Schema from './schema';
7
- interface RawEnum {
7
+ export interface RawEnum {
8
8
  name: string;
9
9
  token: Token;
10
10
  values: EnumValue[];
@@ -2,7 +2,7 @@ import { NormalizedModel } from './database';
2
2
  import DbState from './dbState';
3
3
  import Element, { Token, RawNote } from './element';
4
4
  import Enum from './enum';
5
- interface RawEnumValue {
5
+ export interface RawEnumValue {
6
6
  name: string;
7
7
  token: Token;
8
8
  note: RawNote;
@@ -1,7 +1,15 @@
1
1
  import { NormalizedModel } from './database';
2
2
  import DbState from './dbState';
3
- import Element from './element';
3
+ import Element, { Token } from './element';
4
4
  import Index from './indexes';
5
+
6
+ export interface RawIndexColumn {
7
+ type: any;
8
+ value: any;
9
+ index: Index;
10
+ token: Token;
11
+ }
12
+
5
13
  declare class IndexColumn extends Element {
6
14
  type: any;
7
15
  value: any;
@@ -4,7 +4,7 @@ import Element, { RawNote, Token } from './element';
4
4
  import IndexColumn from './indexColumn';
5
5
  import Table from './table';
6
6
  import TablePartial from './tablePartial';
7
- interface RawIndex {
7
+ export interface RawIndex {
8
8
  columns: IndexColumn;
9
9
  type: any;
10
10
  unique: boolean;
@@ -4,7 +4,7 @@ import Schema from './schema';
4
4
  import DbState from './dbState';
5
5
  import Database, { NormalizedModel } from './database';
6
6
  import TablePartial from './tablePartial';
7
- interface RawRef {
7
+ export interface RawRef {
8
8
  name: string;
9
9
  color?: string;
10
10
  endpoints: Endpoint[];
@@ -6,9 +6,9 @@ import Schema from './schema';
6
6
  import DbState from './dbState';
7
7
  import TableGroup from './tableGroup';
8
8
  import TablePartial from './tablePartial';
9
- import { NormalizedModel } from './database';
9
+ import { NormalizedModel, TableRecord } from './database';
10
10
 
11
- interface RawTable {
11
+ export interface RawTable {
12
12
  name: string;
13
13
  alias: string;
14
14
  note: RawNote;
@@ -35,6 +35,7 @@ declare class Table extends Element {
35
35
  id: number;
36
36
  group: TableGroup;
37
37
  partials: TablePartial[];
38
+ records: TableRecord[];
38
39
 
39
40
  constructor({ name, alias, note, fields, indexes, checks, schema, token, headerColor }: RawTable);
40
41
  generateId(): void;
@@ -115,6 +116,7 @@ declare class Table extends Element {
115
116
  note: string;
116
117
  headerColor: string;
117
118
  partials: TablePartial[];
119
+ recordIds: number[];
118
120
  };
119
121
  normalize(model: NormalizedModel): void;
120
122
  }
@@ -128,6 +130,7 @@ export interface NormalizedTable {
128
130
  fieldIds: number[];
129
131
  indexIds: number[];
130
132
  checkIds: number[];
133
+ recordIds: number[];
131
134
  schemaId: number;
132
135
  groupId: number | null;
133
136
  partials: TablePartial[];
@@ -4,7 +4,7 @@ import Element, { RawNote, Token} from './element';
4
4
  import Schema from './schema';
5
5
  import Table from './table';
6
6
 
7
- interface RawTableGroup {
7
+ export interface RawTableGroup {
8
8
  name: string;
9
9
  tables: Table[];
10
10
  schema: Schema;
@@ -5,7 +5,7 @@ import Check from './check';
5
5
  import DbState from './dbState';
6
6
  import { NormalizedModel } from './database';
7
7
 
8
- interface RawTablePartial {
8
+ export interface RawTablePartial {
9
9
  name: string;
10
10
  note: RawNote;
11
11
  fields: Field[];