@rdbms-erd/core 0.1.2 → 0.1.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,237 @@
1
+ type AlignCommand = "left" | "h-center" | "right" | "top" | "v-center" | "bottom" | "h-gap" | "v-gap";
2
+ /**
3
+ * 멀티 선택된 노드 위치를 bounding box 기준으로 정렬/분배한다.
4
+ * positions는 id -> 좌표 맵이며, 반환값은 동일 키에 갱신된 좌표만 포함한다.
5
+ */
6
+ declare function alignNodePositions(selectedIds: string[], positions: Record<string, {
7
+ x: number;
8
+ y: number;
9
+ }>, command: AlignCommand): Record<string, {
10
+ x: number;
11
+ y: number;
12
+ }>;
13
+
14
+ type BuiltinRdbmsDialect = "mssql" | "oracle" | "mysql" | "postgres" | "sqlite";
15
+ type RdbmsDialect = BuiltinRdbmsDialect | (string & {});
16
+
17
+ declare const LOGICAL_DATA_TYPES: readonly ["TEXT", "DATE", "TIME", "DATETIME", "NUMBER", "DECIMAL", "FLOAT", "BOOLEAN", "JSON", "UUID", "BINARY"];
18
+ type LogicalDataType = (typeof LOGICAL_DATA_TYPES)[number];
19
+ interface ColumnModel {
20
+ id: string;
21
+ logicalName: string;
22
+ physicalName: string;
23
+ /** 컬럼 설명(업무/도메인 메모). */
24
+ description?: string;
25
+ logicalType: LogicalDataType;
26
+ physicalType: string;
27
+ defaultValue?: string;
28
+ nullable: boolean;
29
+ isPrimaryKey?: boolean;
30
+ isForeignKey?: boolean;
31
+ referencesPrimaryColumnId?: string;
32
+ /** 테이블 노드에서 해당 컬럼 행 배경색 */
33
+ color?: string;
34
+ }
35
+ interface TableModel {
36
+ id: string;
37
+ logicalName: string;
38
+ physicalName: string;
39
+ /** 테이블 설명(업무/도메인 메모). */
40
+ description?: string;
41
+ /** Dialect-dependent schema/catalog qualifier (e.g. `public`, `dbo`). */
42
+ schemaName?: string;
43
+ color?: string;
44
+ columns: ColumnModel[];
45
+ }
46
+ interface RelationshipModel {
47
+ id: string;
48
+ /** 참조 원본(PK) 테이블 */
49
+ sourceTableId: string;
50
+ /** 참조 대상(FK) 테이블 */
51
+ targetTableId: string;
52
+ /** source(PK) 컬럼 id */
53
+ sourceColumnId?: string;
54
+ /** target(FK) 컬럼 id */
55
+ targetColumnId?: string;
56
+ /** 연결 시 생성된 FK 컬럼인지 여부(삭제 시 컬럼 정리용) */
57
+ autoCreatedTargetColumn?: boolean;
58
+ /** FK가 최초로 연결된 PK 컬럼 id(컬럼명 변경과 무관) */
59
+ originPkColumnId?: string;
60
+ /** 타깃 cardinality. 기본 1:N */
61
+ cardinality?: "1:1" | "1:N";
62
+ /** 출발(소스) 엣지의 테이블 내부 절대 Y 좌표(px). */
63
+ sourceLineY?: number;
64
+ /** @deprecated legacy ratio(0~1). sourceLineY가 없을 때만 fallback으로 사용 */
65
+ sourceLineRatio?: number;
66
+ /** 관계선의 중간 꺾임 위치 비율(0~1). 두 테이블 앵커 사이의 비율로 저장한다. */
67
+ linePivotRatio?: number;
68
+ /** true이면 캔버스에서 해당 관계선을 기본적으로 숨긴다. 툴의「숨긴 관계선 보기」로만 표시 가능. */
69
+ canvasLineHidden?: boolean;
70
+ }
71
+ /**
72
+ * 캔버스에 관계선을 그릴지 여부.
73
+ * - `revealHiddenLines === false`: `canvasLineHidden`인 관계는 제외.
74
+ * - `revealHiddenLines === true`: 숨김 처리된 관계도 함께 그린다(표시만, 속성은 바꾸지 않음).
75
+ */
76
+ declare function isRelationshipLineRenderable(rel: RelationshipModel, revealHiddenLines: boolean): boolean;
77
+ /** 구버전 `ColumnModel.showFkRelationLine === false`를 관계의 `canvasLineHidden`으로 옮긴 뒤 컬럼 플래그를 제거한다. */
78
+ declare function migrateLegacyFkLineVisibility(model: DesignModel): void;
79
+ interface IndexModel {
80
+ id: string;
81
+ tableId: string;
82
+ name: string;
83
+ columns: string[];
84
+ unique: boolean;
85
+ }
86
+ interface DiagramLayout {
87
+ nodePositions: Record<string, {
88
+ x: number;
89
+ y: number;
90
+ }>;
91
+ }
92
+ interface DesignModel {
93
+ dialect: RdbmsDialect;
94
+ tables: TableModel[];
95
+ relationships: RelationshipModel[];
96
+ indexes: IndexModel[];
97
+ }
98
+ interface DesignDocument {
99
+ schemaVersion: number;
100
+ model: DesignModel;
101
+ layout: DiagramLayout;
102
+ settings?: Record<string, unknown>;
103
+ }
104
+ interface DialectCapability {
105
+ supportsSchema: boolean;
106
+ }
107
+ type DdlStyleQuote = "double" | "backtick" | "bracket";
108
+ type DdlStyleBooleanLiteral = "trueFalse" | "oneZero";
109
+ interface DdlStyle {
110
+ quote: DdlStyleQuote;
111
+ boolLiteral?: DdlStyleBooleanLiteral;
112
+ nowKeyword?: string;
113
+ }
114
+ interface LogicalTypeMeta {
115
+ id: LogicalDataType;
116
+ label?: string;
117
+ defaultPhysicalType: string;
118
+ }
119
+ interface DialectMetaJson {
120
+ id: RdbmsDialect;
121
+ label: string;
122
+ supportsSchema: boolean;
123
+ logicalTypes: LogicalTypeMeta[];
124
+ ddlStyle?: DdlStyle;
125
+ }
126
+ interface DialectMeta {
127
+ id: RdbmsDialect;
128
+ label: string;
129
+ capabilities: DialectCapability;
130
+ logicalTypes: readonly LogicalDataType[];
131
+ defaultPhysicalTypeMap: Partial<Record<LogicalDataType, string>>;
132
+ }
133
+ type DdlScope = {
134
+ kind: "all";
135
+ } | {
136
+ kind: "selected";
137
+ tableIds: string[];
138
+ };
139
+ interface DdlGenerateInput {
140
+ doc: DesignDocument;
141
+ dialectId: RdbmsDialect;
142
+ scope: DdlScope;
143
+ }
144
+ interface DdlGenerateOutput {
145
+ sql: string;
146
+ diagnostics?: DdlDiagnostic[];
147
+ }
148
+ type DdlGeneratorHook = (input: DdlGenerateInput) => DdlGenerateOutput | Promise<DdlGenerateOutput>;
149
+ interface DdlGeneratorRules {
150
+ quoteIdentifier?: (dialect: RdbmsDialect, identifier: string) => string;
151
+ toDefaultExpression?: (dialect: RdbmsDialect, col: ColumnModel) => string | null;
152
+ }
153
+ interface DbMetaAdapter {
154
+ listDialects: () => DialectMeta[];
155
+ getDialectMeta: (dialect: RdbmsDialect) => DialectMeta | undefined;
156
+ getDefaultPhysicalType: (dialect: RdbmsDialect, logicalType: LogicalDataType) => string;
157
+ getDdlRules: (dialect: RdbmsDialect) => DdlGeneratorRules;
158
+ }
159
+ interface CoreDbMetaOptions {
160
+ dbMetaAdapter?: DbMetaAdapter;
161
+ hostMetas?: DialectMetaJson[];
162
+ hostDdlGenerators?: Record<string, DdlGeneratorHook>;
163
+ fallbackOnHookError?: boolean;
164
+ }
165
+ declare const BUILTIN_DIALECTS: readonly BuiltinRdbmsDialect[];
166
+ declare const BUILTIN_DIALECT_METAS_JSON: DialectMetaJson[];
167
+ declare function mergeDialectMetas(base: DialectMetaJson[], host?: DialectMetaJson[]): DialectMetaJson[];
168
+ declare function resolveDialectMetas(options?: CoreDbMetaOptions): DialectMetaJson[];
169
+ declare function createDefaultDbMetaAdapter(overrides?: Partial<DbMetaAdapter>): DbMetaAdapter;
170
+ declare const defaultDbMetaAdapter: DbMetaAdapter;
171
+ declare function defaultPhysicalType(dialect: RdbmsDialect, logicalType: LogicalDataType, options?: CoreDbMetaOptions): string;
172
+ /**
173
+ * 물리 데이터 유형 문자열에서 방언 메타의 기본 매핑(및 흔한 SQL 별칭)으로 논리 유형을 추정한다.
174
+ */
175
+ declare function inferLogicalTypeFromPhysical(dialect: RdbmsDialect, physicalType: string, options?: CoreDbMetaOptions): LogicalDataType;
176
+ declare function getRdbmsDialectCapability(dialect: RdbmsDialect, options?: CoreDbMetaOptions): DialectCapability;
177
+ declare function dialectSupportsSchema(dialect: RdbmsDialect, options?: CoreDbMetaOptions): boolean;
178
+ declare function convertDesignDialect(doc: DesignDocument, nextDialect: RdbmsDialect, options?: CoreDbMetaOptions): DesignDocument;
179
+ declare function applyLogicalTypeChange(column: ColumnModel, nextLogicalType: LogicalDataType, dialect: RdbmsDialect, options?: CoreDbMetaOptions): ColumnModel;
180
+ declare function createColumn(dialect: RdbmsDialect, params: {
181
+ id: string;
182
+ logicalName: string;
183
+ /** 생략 시 논리 이름과 동일한 물리 이름으로 생성된다. */
184
+ physicalName?: string;
185
+ description?: string;
186
+ logicalType: LogicalDataType;
187
+ defaultValue?: string;
188
+ nullable?: boolean;
189
+ isPrimaryKey?: boolean;
190
+ isForeignKey?: boolean;
191
+ referencesPrimaryColumnId?: string;
192
+ color?: string;
193
+ }, options?: CoreDbMetaOptions): ColumnModel;
194
+ declare function createEmptyDesign(dialect?: RdbmsDialect): DesignDocument;
195
+ declare function serializeDesign(doc: DesignDocument): string;
196
+ declare function parseDesign(json: string, options?: CoreDbMetaOptions): DesignDocument;
197
+ declare function validateDesignDocument(input: unknown, options?: CoreDbMetaOptions): DesignDocument;
198
+ declare function roundTripDesign(doc: DesignDocument): DesignDocument;
199
+ /** DDL/인덱스 분석 공통 심각도 */
200
+ type DdlDiagnosticSeverity = "error" | "warning";
201
+ /** 구조화된 DDL 관련 진단(에러·경고) */
202
+ interface DdlDiagnostic {
203
+ severity: DdlDiagnosticSeverity;
204
+ code: string;
205
+ message: string;
206
+ /** 예: relationship:rel1, index:ix1, table:t1 */
207
+ context?: string;
208
+ }
209
+ /**
210
+ * 통일된 한 줄 텍스트 포맷.
211
+ * 예: `[WARN][DDL_REL_MISSING_COLUMNS] ... | relationship:rel1`
212
+ */
213
+ declare function formatDdlDiagnostic(d: DdlDiagnostic): string;
214
+ declare function formatDdlDiagnostics(diagnostics: DdlDiagnostic[]): string;
215
+ /**
216
+ * 모델 전체에 대한 DDL·인덱스 관련 진단(테이블/관계/인덱스).
217
+ * 검증 예외(Invalid design document)와는 별도로, 생성 가능 여부와 경고를 나열한다.
218
+ */
219
+ declare function analyzeDdlDocument(doc: DesignDocument, options?: CoreDbMetaOptions): DdlDiagnostic[];
220
+ declare function generateDdlWithDiagnostics(doc: DesignDocument, options?: CoreDbMetaOptions): {
221
+ sql: string;
222
+ diagnostics: DdlDiagnostic[];
223
+ };
224
+ declare function generateIndexDdlWithDiagnostics(doc: DesignDocument, options?: CoreDbMetaOptions): {
225
+ sql: string;
226
+ diagnostics: DdlDiagnostic[];
227
+ };
228
+ declare function generateDdl(doc: DesignDocument, options?: CoreDbMetaOptions): string;
229
+ declare function generateDdlForSelection(doc: DesignDocument, tableIds: string[], options?: CoreDbMetaOptions): {
230
+ sql: string;
231
+ diagnostics: DdlDiagnostic[];
232
+ };
233
+ declare function generateIndexDdl(doc: DesignDocument, options?: CoreDbMetaOptions): string;
234
+ /** 성능·부하 테스트용: 지정 개수의 빈 테이블과 격자 레이아웃을 생성한다. */
235
+ declare function createLargeDesign(tableCount: number, dialect?: RdbmsDialect): DesignDocument;
236
+
237
+ export { type AlignCommand, BUILTIN_DIALECTS, BUILTIN_DIALECT_METAS_JSON, type BuiltinRdbmsDialect, type ColumnModel, type CoreDbMetaOptions, type DbMetaAdapter, type DdlDiagnostic, type DdlDiagnosticSeverity, type DdlGenerateInput, type DdlGenerateOutput, type DdlGeneratorHook, type DdlGeneratorRules, type DdlScope, type DdlStyle, type DdlStyleBooleanLiteral, type DdlStyleQuote, type DesignDocument, type DesignModel, type DiagramLayout, type DialectCapability, type DialectMeta, type DialectMetaJson, type IndexModel, LOGICAL_DATA_TYPES, type LogicalDataType, type LogicalTypeMeta, type RdbmsDialect, type RelationshipModel, type TableModel, alignNodePositions, analyzeDdlDocument, applyLogicalTypeChange, convertDesignDialect, createColumn, createDefaultDbMetaAdapter, createEmptyDesign, createLargeDesign, defaultDbMetaAdapter, defaultPhysicalType, dialectSupportsSchema, formatDdlDiagnostic, formatDdlDiagnostics, generateDdl, generateDdlForSelection, generateDdlWithDiagnostics, generateIndexDdl, generateIndexDdlWithDiagnostics, getRdbmsDialectCapability, inferLogicalTypeFromPhysical, isRelationshipLineRenderable, mergeDialectMetas, migrateLegacyFkLineVisibility, parseDesign, resolveDialectMetas, roundTripDesign, serializeDesign, validateDesignDocument };