Skip to content

Commit

Permalink
Create index.d.ts file
Browse files Browse the repository at this point in the history
  • Loading branch information
youngkiu committed Oct 30, 2022
1 parent 14bb946 commit b80c7e2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Generate ERD UML file from Schema DDL file",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "./src/index.d.ts",
"files": [
"dist"
],
Expand Down
11 changes: 11 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type parseDdlType = {
[tableName: string]: {
columnNames: string[],
primaryKeys: string[],
}
};

export type pumlOutputType = {
pumlFilePath: string;
pumlStr: string;
};
8 changes: 1 addition & 7 deletions src/parse_ddl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Parser } from 'sql-ddl-to-json-schema';
import assert from 'assert';
import { JSONSchema7 } from 'json-schema';
import config from './unparsable.config';
import { parseDdlType } from './index.d';

const parser = new Parser('mysql');

Expand Down Expand Up @@ -128,13 +129,6 @@ const removeSqlComments = (sqlStr: string): string => sqlStr
.replace(/COMMENT\s+['"](.*?)['"]/gi, '') // https://stackoverflow.com/a/171483
.replace(/\/\*.*?\*\/|--.*?\n/gs, ''); // https://stackoverflow.com/a/21018155

export type parseDdlType = {
[tableName: string]: {
columnNames: string[],
primaryKeys: string[],
}
};

export default (sqlStr: string): parseDdlType => splitDdl(removeSqlComments(sqlStr))
.reduce(
(acc, sql) => {
Expand Down
2 changes: 1 addition & 1 deletion src/plantuml_table.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseDdlType } from './parse_ddl';
import { parseDdlType } from './index.d';

function generateEntity(
tableName: string,
Expand Down
8 changes: 2 additions & 6 deletions src/schema_to_erd.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { promises as fs } from 'fs';
import path from 'path';
import { PathLike } from 'node:fs';
import parseDdl, { parseDdlType } from './parse_ddl';
import parseDdl from './parse_ddl';
import generatePlantUml from './plantuml_table';

export type pumlOutputType = {
pumlFilePath: string;
pumlStr: string;
};
import { parseDdlType, pumlOutputType } from './index.d';

export default async function schemaToErd(
schemaFilePath: PathLike,
Expand Down

0 comments on commit b80c7e2

Please sign in to comment.