Skip to content

Commit d24a249

Browse files
authored
Merge pull request #821 from holistics/chore/expose-non-normalized-model-structure-types
Expose non-normalized model structure types
2 parents 10e5ddf + 647b7e7 commit d24a249

6 files changed

Lines changed: 37 additions & 117 deletions

File tree

packages/dbml-core/types/index.d.ts

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,4 @@ import { renameTable } from './transform';
66
export { renameTable, importer, exporter, ModelExporter, Parser };
77
export { CompilerDiagnostic, CompilerError as CompilerDiagnostics, EditorPosition, ErrorCode, WarningLevel, } from './parse/error';
88

9-
// Export normalized types
10-
export type {
11-
NormalizedDatabase,
12-
NormalizedDatabaseIdMap,
13-
NormalizedModel,
14-
NormalizedSchema,
15-
NormalizedSchemaIdMap,
16-
NormalizedTable,
17-
NormalizedTableIdMap,
18-
NormalizedField,
19-
NormalizedFieldIdMap,
20-
NormalizedIndex,
21-
NormalizedIndexIdMap,
22-
NormalizedIndexColumn,
23-
NormalizedIndexColumnIdMap,
24-
NormalizedEnum,
25-
NormalizedEnumIdMap,
26-
NormalizedEnumValue,
27-
NormalizedEnumValueIdMap,
28-
NormalizedRef,
29-
NormalizedRefIdMap,
30-
NormalizedEndpoint,
31-
NormalizedEndpointIdMap,
32-
NormalizedTableGroup,
33-
NormalizedTableGroupIdMap,
34-
NormalizedNote,
35-
NormalizedNoteIdMap,
36-
NormalizedCheck,
37-
NormalizedCheckIdMap,
38-
NormalizedTablePartial,
39-
NormalizedTablePartialIdMap,
40-
Project,
41-
RawDatabase,
42-
TableRecord,
43-
NormalizedRecords,
44-
RawSchema,
45-
} from './model_structure';
9+
export * from './model_structure';

packages/dbml-core/types/model_structure/database.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ export interface TableRecord extends RawTableRecord {
3333
id: number;
3434
}
3535

36-
export interface NormalizedRecords {
37-
[_id: number]: TableRecord;
36+
export type NormalizedRecord = TableRecord;
37+
38+
export interface NormalizedRecordIdMap {
39+
[_id: number]: NormalizedRecord;
3840
}
3941

4042
export interface RawDatabase {
@@ -307,5 +309,6 @@ export interface NormalizedModel {
307309
notes: NormalizedNoteIdMap;
308310
checks: NormalizedCheckIdMap;
309311
tablePartials: NormalizedTablePartialIdMap;
312+
records: NormalizedRecordIdMap;
310313
}
311314
export default Database;

packages/dbml-core/types/model_structure/endpoint.d.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
import Element from './element';
1+
import Element, { Token } from './element';
22
import Field from './field';
33
import Ref from './ref';
44
import DbState from './dbState';
55
import { NormalizedModel } from './database';
6+
7+
export interface RawEndpoint {
8+
schemaName: string | null;
9+
tableName: string;
10+
fieldNames: string[];
11+
relation: '1' | '*';
12+
token: Token;
13+
}
14+
615
declare class Endpoint extends Element {
716
relation: any;
817
schemaName: string;

packages/dbml-core/types/model_structure/field.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ interface RawField {
1414
token: Token;
1515
not_null: boolean;
1616
note: RawNote;
17-
dbdefault: any;
17+
dbdefault?: {
18+
type: 'number' | 'string' | 'boolean' | 'expression';
19+
value: number | string;
20+
};
1821
increment: boolean;
1922
checks?: any[];
2023
table: Table;

packages/dbml-core/types/model_structure/index.d.ts

Lines changed: 14 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -14,78 +14,17 @@ export { default as StickyNote } from './stickyNote';
1414
export { default as Check } from './check';
1515
export { default as TablePartial } from './tablePartial';
1616

17-
// Export normalized individual types
18-
export type {
19-
NormalizedDatabase,
20-
NormalizedDatabaseIdMap,
21-
NormalizedModel,
22-
} from './database';
23-
24-
export type {
25-
NormalizedSchema,
26-
NormalizedSchemaIdMap,
27-
} from './schema';
28-
29-
export type {
30-
NormalizedTable,
31-
NormalizedTableIdMap,
32-
} from './table';
33-
34-
export type {
35-
NormalizedField,
36-
NormalizedFieldIdMap,
37-
} from './field';
38-
39-
export type {
40-
NormalizedIndex,
41-
NormalizedIndexIdMap,
42-
} from './indexes';
43-
44-
export type {
45-
NormalizedIndexColumn,
46-
NormalizedIndexColumnIdMap,
47-
} from './indexColumn';
48-
49-
export type {
50-
NormalizedEnum,
51-
NormalizedEnumIdMap,
52-
} from './enum';
53-
54-
export type {
55-
NormalizedEnumValue,
56-
NormalizedEnumValueIdMap,
57-
} from './enumValue';
58-
59-
export type {
60-
NormalizedRef,
61-
NormalizedRefIdMap,
62-
} from './ref';
63-
64-
export type {
65-
NormalizedEndpoint,
66-
NormalizedEndpointIdMap,
67-
} from './endpoint';
68-
69-
export type {
70-
NormalizedTableGroup,
71-
NormalizedTableGroupIdMap,
72-
} from './tableGroup';
73-
74-
export type {
75-
NormalizedNote,
76-
NormalizedNoteIdMap,
77-
} from './stickyNote';
78-
79-
export type {
80-
NormalizedTablePartial,
81-
NormalizedTablePartialIdMap,
82-
} from './tablePartial';
83-
84-
export type {
85-
NormalizedCheck,
86-
NormalizedCheckIdMap,
87-
} from './check';
88-
89-
// Export other types
90-
export type { Project, RawDatabase, TableRecord, NormalizedRecords } from './database';
91-
export type { RawSchema } from './schema';
17+
export * from './database';
18+
export * from './schema';
19+
export * from './table';
20+
export * from './field';
21+
export * from './indexes';
22+
export * from './indexColumn';
23+
export * from './enum';
24+
export * from './enumValue';
25+
export * from './ref';
26+
export * from './endpoint';
27+
export * from './tableGroup';
28+
export * from './stickyNote';
29+
export * from './tablePartial';
30+
export * from './check';

packages/dbml-core/types/model_structure/stickyNote.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import Element, { Token } from './element';
22
import Database from './database';
33
import DbState from './dbState';
44
import { NormalizedModel } from './database';
5-
interface RawStickyNote {
5+
6+
export interface RawStickyNote {
67
name: string;
78
content: string;
89
database: Database;
910
token: Token;
1011
headerColor: string;
1112
}
13+
1214
declare class StickyNote extends Element {
1315
name: string;
1416
content: string;

0 commit comments

Comments
 (0)