From b80c7e2b18ed0e9c684c174ec929c59e6cf8a427 Mon Sep 17 00:00:00 2001 From: YoungKi Lyu Date: Sun, 30 Oct 2022 19:33:22 +0900 Subject: [PATCH] Create index.d.ts file --- package.json | 1 + src/index.d.ts | 11 +++++++++++ src/parse_ddl.ts | 8 +------- src/plantuml_table.ts | 2 +- src/schema_to_erd.ts | 8 ++------ 5 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 src/index.d.ts diff --git a/package.json b/package.json index 67ac66d..997d32d 100644 --- a/package.json +++ b/package.json @@ -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" ], diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..07f6eb8 --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,11 @@ +export type parseDdlType = { + [tableName: string]: { + columnNames: string[], + primaryKeys: string[], + } +}; + +export type pumlOutputType = { + pumlFilePath: string; + pumlStr: string; +}; diff --git a/src/parse_ddl.ts b/src/parse_ddl.ts index bf29d31..ef81d8b 100644 --- a/src/parse_ddl.ts +++ b/src/parse_ddl.ts @@ -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'); @@ -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) => { diff --git a/src/plantuml_table.ts b/src/plantuml_table.ts index 7e1538b..c26c1e4 100644 --- a/src/plantuml_table.ts +++ b/src/plantuml_table.ts @@ -1,4 +1,4 @@ -import { parseDdlType } from './parse_ddl'; +import { parseDdlType } from './index.d'; function generateEntity( tableName: string, diff --git a/src/schema_to_erd.ts b/src/schema_to_erd.ts index 1e38678..73e14e5 100644 --- a/src/schema_to_erd.ts +++ b/src/schema_to_erd.ts @@ -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,