update dependencies

This commit is contained in:
Kononnable 2019-12-18 22:24:05 +01:00
parent ddfc9f52d9
commit 57cec40afb
7 changed files with 1664 additions and 899 deletions

View File

@ -28,7 +28,7 @@ module.exports = {
"no-plusplus": ["error", { allowForLoopAfterthoughts: true }],
"@typescript-eslint/no-non-null-assertion": ["off"],
"import/extensions": ["off"],
"no-param-reassign": ["off"],
"@typescript-eslint/no-explicit-any": ["off"],
"no-loop-func": ["off"]

2140
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -24,63 +24,63 @@
},
"homepage": "https://github.com/Kononnable/typeorm-model-generator#readme",
"dependencies": {
"change-case": "^3.1.0",
"change-case": "^4.1.0",
"fs-extra": "^8.1.0",
"handlebars": "^4.4.3",
"inquirer": "^7.0.0",
"mssql": "^5.1.0",
"handlebars": "^4.5.3",
"inquirer": "^7.0.1",
"mssql": "^6.0.1",
"mysql": "^2.17.1",
"pg": "^7.12.1",
"pg": "^7.15.0",
"pluralize": "^8.0.0",
"prettier": "^1.18.2",
"prettier": "^1.19.1",
"reflect-metadata": "^0.1.13",
"sqlite3": "^4.1.0",
"typeorm": "^0.2.19",
"typescript": "^3.6.4",
"yargs": "^14.2.0",
"sqlite3": "^4.1.1",
"typeorm": "^0.2.21",
"typescript": "^3.7.3",
"yargs": "^15.0.2",
"yn": "^3.1.1"
},
"devDependencies": {
"@types/array.prototype.flatmap": "^1.2.0",
"@types/chai": "^4.2.3",
"@types/chai": "^4.2.7",
"@types/chai-as-promised": "^7.1.2",
"@types/chai-subset": "^1.3.3",
"@types/fs-extra": "^8.0.0",
"@types/fs-extra": "^8.0.1",
"@types/handlebars": "^4.1.0",
"@types/inquirer": "^6.5.0",
"@types/mocha": "^5.2.7",
"@types/mssql": "^4.3.1",
"@types/mysql": "^2.15.7",
"@types/node": "^12.7.12",
"@types/oracledb": "^4.0.4",
"@types/mssql": "^6.0.0",
"@types/mysql": "^2.15.8",
"@types/node": "^12.12.21",
"@types/oracledb": "^4.1.1",
"@types/pg": "^7.11.2",
"@types/pluralize": "0.0.29",
"@types/prettier": "^1.18.3",
"@types/sinon": "^7.5.0",
"@types/prettier": "^1.19.0",
"@types/sinon": "^7.5.1",
"@types/sqlite3": "^3.1.5",
"@types/yargs": "^13.0.3",
"@typescript-eslint/eslint-plugin": "^2.3.3",
"@typescript-eslint/parser": "^2.3.3",
"@typescript-eslint/typescript-estree": "^2.3.3",
"array.prototype.flatmap": "^1.2.2",
"@typescript-eslint/eslint-plugin": "^2.12.0",
"@typescript-eslint/parser": "^2.12.0",
"@typescript-eslint/typescript-estree": "^2.12.0",
"array.prototype.flatmap": "^1.2.3",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"chai-subset": "^1.6.0",
"codecov": "^3.6.1",
"dotenv": "^8.1.0",
"eslint": "^6.5.1",
"dotenv": "^8.2.0",
"eslint": "^6.7.2",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.4.0",
"eslint-plugin-import": "^2.18.2",
"husky": "^3.0.8",
"lint-staged": "^9.4.2",
"mocha": "^6.2.1",
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-import": "^2.19.1",
"husky": "^3.1.0",
"lint-staged": "^9.5.0",
"mocha": "^6.2.2",
"ncp": "^2.0.0",
"nyc": "^14.1.1",
"rimraf": "^3.0.0",
"sinon": "^7.5.0",
"sinon-chai": "^3.3.0",
"ts-node": "^8.4.1"
"ts-node": "^8.5.4"
},
"husky": {
"hooks": {

View File

@ -30,12 +30,14 @@ export default class MssqlDriver extends AbstractDriver {
TABLE_SCHEMA: string;
TABLE_NAME: string;
DB_NAME: string;
}[] = (await request.query(
`SELECT TABLE_SCHEMA,TABLE_NAME, table_catalog as "DB_NAME" FROM INFORMATION_SCHEMA.TABLES
}[] = (
await request.query(
`SELECT TABLE_SCHEMA,TABLE_NAME, table_catalog as "DB_NAME" FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE='BASE TABLE' and TABLE_SCHEMA in (${schema}) AND TABLE_CATALOG in (${MssqlDriver.escapeCommaSeparatedList(
dbNames
)})`
)).recordset;
dbNames
)})`
)
).recordset;
return response;
};
@ -56,7 +58,8 @@ WHERE TABLE_TYPE='BASE TABLE' and TABLE_SCHEMA in (${schema}) AND TABLE_CATALOG
NUMERIC_SCALE: number;
IsIdentity: number;
IsUnique: number;
}[] = (await request.query(`SELECT TABLE_NAME,COLUMN_NAME,COLUMN_DEFAULT,IS_NULLABLE,
}[] = (
await request.query(`SELECT TABLE_NAME,COLUMN_NAME,COLUMN_DEFAULT,IS_NULLABLE,
DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,
COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') IsIdentity,
(SELECT count(*)
@ -70,9 +73,10 @@ WHERE TABLE_TYPE='BASE TABLE' and TABLE_SCHEMA in (${schema}) AND TABLE_CATALOG
and tc.TABLE_SCHEMA=c.TABLE_SCHEMA) IsUnique
FROM INFORMATION_SCHEMA.COLUMNS c
where TABLE_SCHEMA in (${schema}) AND TABLE_CATALOG in (${MssqlDriver.escapeCommaSeparatedList(
dbNames
)})
order by ordinal_position`)).recordset;
dbNames
)})
order by ordinal_position`)
).recordset;
entities.forEach(ent => {
response
.filter(filterVal => {
@ -256,7 +260,8 @@ WHERE TABLE_TYPE='BASE TABLE' and TABLE_SCHEMA in (${schema}) AND TABLE_CATALOG
ColumnName: string;
is_unique: boolean;
is_primary_key: boolean;
}[] = (await request.query(`SELECT
}[] = (
await request.query(`SELECT
TableName = t.name,
IndexName = ind.name,
ColumnName = col.name,
@ -275,7 +280,8 @@ WHERE TABLE_TYPE='BASE TABLE' and TABLE_SCHEMA in (${schema}) AND TABLE_CATALOG
WHERE
t.is_ms_shipped = 0 and s.name in (${schema})
ORDER BY
t.name, ind.name, ind.index_id, ic.key_ordinal;`)).recordset;
t.name, ind.name, ind.index_id, ic.key_ordinal;`)
).recordset;
response.push(...resp);
})
);
@ -335,7 +341,8 @@ WHERE TABLE_TYPE='BASE TABLE' and TABLE_SCHEMA in (${schema}) AND TABLE_CATALOG
onDelete: "RESTRICT" | "CASCADE" | "SET_NULL" | "NO_ACTION";
onUpdate: "RESTRICT" | "CASCADE" | "SET_NULL" | "NO_ACTION";
objectId: number;
}[] = (await request.query(`select
}[] = (
await request.query(`select
parentTable.name as TableWithForeignKey,
fkc.constraint_column_id as FK_PartNo,
parentColumn.name as ForeignKeyColumn,
@ -361,7 +368,8 @@ WHERE TABLE_TYPE='BASE TABLE' and TABLE_SCHEMA in (${schema}) AND TABLE_CATALOG
where
fk.is_disabled=0 and fk.is_ms_shipped=0 and parentSchema.name in (${schema})
order by
TableWithForeignKey, FK_PartNo`)).recordset;
TableWithForeignKey, FK_PartNo`)
).recordset;
response.push(...resp);
})
);

View File

@ -41,9 +41,11 @@ export default class OracleDriver extends AbstractDriver {
TABLE_SCHEMA: string;
TABLE_NAME: string;
DB_NAME: string;
}[] = (await this.Connection.execute(
`SELECT NULL AS TABLE_SCHEMA, TABLE_NAME, NULL AS DB_NAME FROM all_tables WHERE owner = (select user from dual)`
)).rows!;
}[] = (
await this.Connection.execute(
`SELECT NULL AS TABLE_SCHEMA, TABLE_NAME, NULL AS DB_NAME FROM all_tables WHERE owner = (select user from dual)`
)
).rows!;
return response;
};
@ -59,11 +61,13 @@ export default class OracleDriver extends AbstractDriver {
DATA_SCALE: number;
IDENTITY_COLUMN: string; // doesn't exist in old oracle versions (#195)
IS_UNIQUE: number;
}[] = (await this.Connection
.execute(`SELECT utc.*, (select count(*) from USER_CONS_COLUMNS ucc
}[] = (
await this.Connection
.execute(`SELECT utc.*, (select count(*) from USER_CONS_COLUMNS ucc
JOIN USER_CONSTRAINTS uc ON uc.CONSTRAINT_NAME = ucc.CONSTRAINT_NAME and uc.CONSTRAINT_TYPE='U'
where ucc.column_name = utc.COLUMN_NAME AND ucc.table_name = utc.TABLE_NAME) IS_UNIQUE
FROM USER_TAB_COLUMNS utc`)).rows!;
FROM USER_TAB_COLUMNS utc`)
).rows!;
entities.forEach(ent => {
response
@ -221,12 +225,14 @@ export default class OracleDriver extends AbstractDriver {
INDEX_NAME: string;
UNIQUENESS: string;
ISPRIMARYKEY: number;
}[] = (await this.Connection
.execute(`SELECT ind.TABLE_NAME, ind.INDEX_NAME, col.COLUMN_NAME,ind.UNIQUENESS, CASE WHEN uc.CONSTRAINT_NAME IS NULL THEN 0 ELSE 1 END ISPRIMARYKEY
}[] = (
await this.Connection
.execute(`SELECT ind.TABLE_NAME, ind.INDEX_NAME, col.COLUMN_NAME,ind.UNIQUENESS, CASE WHEN uc.CONSTRAINT_NAME IS NULL THEN 0 ELSE 1 END ISPRIMARYKEY
FROM USER_INDEXES ind
JOIN USER_IND_COLUMNS col ON ind.INDEX_NAME=col.INDEX_NAME
LEFT JOIN USER_CONSTRAINTS uc ON uc.INDEX_NAME = ind.INDEX_NAME
ORDER BY col.INDEX_NAME ASC ,col.COLUMN_POSITION ASC`)).rows!;
ORDER BY col.INDEX_NAME ASC ,col.COLUMN_POSITION ASC`)
).rows!;
entities.forEach(ent => {
const entityIndices = response.filter(
@ -269,8 +275,9 @@ export default class OracleDriver extends AbstractDriver {
CHILD_COLUMN_NAME: string;
DELETE_RULE: "RESTRICT" | "CASCADE" | "SET NULL" | "NO ACTION";
CONSTRAINT_NAME: string;
}[] = (await this.Connection
.execute(`select owner.TABLE_NAME OWNER_TABLE_NAME,ownCol.POSITION OWNER_POSITION,ownCol.COLUMN_NAME OWNER_COLUMN_NAME,
}[] = (
await this.Connection
.execute(`select owner.TABLE_NAME OWNER_TABLE_NAME,ownCol.POSITION OWNER_POSITION,ownCol.COLUMN_NAME OWNER_COLUMN_NAME,
child.TABLE_NAME CHILD_TABLE_NAME ,childCol.COLUMN_NAME CHILD_COLUMN_NAME,
owner.DELETE_RULE,
owner.CONSTRAINT_NAME
@ -278,8 +285,8 @@ export default class OracleDriver extends AbstractDriver {
join user_constraints child on owner.r_constraint_name=child.CONSTRAINT_NAME and child.constraint_type in ('P','U')
JOIN USER_CONS_COLUMNS ownCol ON owner.CONSTRAINT_NAME = ownCol.CONSTRAINT_NAME
JOIN USER_CONS_COLUMNS childCol ON child.CONSTRAINT_NAME = childCol.CONSTRAINT_NAME AND ownCol.POSITION=childCol.POSITION
ORDER BY OWNER_TABLE_NAME ASC, owner.CONSTRAINT_NAME ASC, OWNER_POSITION ASC`))
.rows!;
ORDER BY OWNER_TABLE_NAME ASC, owner.CONSTRAINT_NAME ASC, OWNER_POSITION ASC`)
).rows!;
const relationsTemp: RelationInternal[] = [] as RelationInternal[];
const relationKeys = new Set(response.map(v => v.CONSTRAINT_NAME));

View File

@ -29,9 +29,11 @@ export default class PostgresDriver extends AbstractDriver {
TABLE_SCHEMA: string;
TABLE_NAME: string;
DB_NAME: string;
}[] = (await this.Connection.query(
`SELECT table_schema as "TABLE_SCHEMA",table_name as "TABLE_NAME", table_catalog as "DB_NAME" FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' AND table_schema in (${schema}) `
)).rows;
}[] = (
await this.Connection.query(
`SELECT table_schema as "TABLE_SCHEMA",table_name as "TABLE_NAME", table_catalog as "DB_NAME" FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' AND table_schema in (${schema}) `
)
).rows;
return response;
};
@ -52,8 +54,9 @@ export default class PostgresDriver extends AbstractDriver {
isidentity: string;
isunique: string;
enumvalues: string | null;
}[] = (await this.Connection
.query(`SELECT table_name,column_name,udt_name,column_default,is_nullable,
}[] = (
await this.Connection
.query(`SELECT table_name,column_name,udt_name,column_default,is_nullable,
data_type,character_maximum_length,numeric_precision,numeric_scale,
case when column_default LIKE 'nextval%' then 'YES' else 'NO' end isidentity,
(SELECT count(*)
@ -74,7 +77,8 @@ export default class PostgresDriver extends AbstractDriver {
) enumValues
FROM INFORMATION_SCHEMA.COLUMNS c
where table_schema in (${schema})
order by ordinal_position`)).rows;
order by ordinal_position`)
).rows;
entities.forEach(ent => {
response
.filter(filterVal => filterVal.table_name === ent.tscName)
@ -414,7 +418,8 @@ export default class PostgresDriver extends AbstractDriver {
columnname: string;
is_unique: number;
is_primary_key: number;
}[] = (await this.Connection.query(`SELECT
}[] = (
await this.Connection.query(`SELECT
c.relname AS tablename,
i.relname as indexname,
f.attname AS columnname,
@ -437,7 +442,8 @@ export default class PostgresDriver extends AbstractDriver {
AND n.nspname in (${schema})
AND f.attnum > 0
AND i.oid<>0
ORDER BY c.relname,f.attname;`)).rows;
ORDER BY c.relname,f.attname;`)
).rows;
entities.forEach(ent => {
const entityIndices = response.filter(
filterVal => filterVal.tablename === ent.tscName
@ -480,7 +486,8 @@ export default class PostgresDriver extends AbstractDriver {
onupdate: "RESTRICT" | "CASCADE" | "SET NULL" | "NO ACTION";
object_id: string;
// Distinct because of note in https://www.postgresql.org/docs/9.1/information-schema.html
}[] = (await this.Connection.query(`SELECT DISTINCT
}[] = (
await this.Connection.query(`SELECT DISTINCT
con.relname AS tablewithforeignkey,
att.attnum as fk_partno,
att2.attname AS foreignkeycolumn,
@ -519,7 +526,8 @@ export default class PostgresDriver extends AbstractDriver {
AND att2.attrelid = con.conrelid
AND att2.attnum = con.parent
AND rc.constraint_name= con.conname AND constraint_catalog=current_database() AND rc.constraint_schema=nspname
`)).rows;
`)
).rows;
const relationsTemp: RelationInternal[] = [] as RelationInternal[];
const relationKeys = new Set(response.map(v => v.object_id));

View File

@ -279,22 +279,24 @@ function checkYargsParameters(options: options): options {
async function useInquirer(options: options): Promise<options> {
const oldDatabaseType = options.connectionOptions.databaseType;
options.connectionOptions.databaseType = (await inquirer.prompt([
{
choices: [
"mssql",
"postgres",
"mysql",
"mariadb",
"oracle",
"sqlite"
],
default: options.connectionOptions.databaseType,
message: "Choose database engine",
name: "engine",
type: "list"
}
])).engine;
options.connectionOptions.databaseType = (
await inquirer.prompt([
{
choices: [
"mssql",
"postgres",
"mysql",
"mariadb",
"oracle",
"sqlite"
],
default: options.connectionOptions.databaseType,
message: "Choose database engine",
name: "engine",
type: "list"
}
])
).engine;
const driver = createDriver(options.connectionOptions.databaseType);
if (options.connectionOptions.databaseType !== oldDatabaseType) {
options.connectionOptions.port = driver.standardPort;
@ -348,15 +350,17 @@ async function useInquirer(options: options): Promise<options> {
options.connectionOptions.databaseType === "mssql" ||
options.connectionOptions.databaseType === "postgres"
) {
options.connectionOptions.schemaName = (await inquirer.prompt([
{
default: options.connectionOptions.schemaName,
message:
"Database schema: (You can pass multiple values separated by comma)",
name: "schema",
type: "input"
}
])).schema;
options.connectionOptions.schemaName = (
await inquirer.prompt([
{
default: options.connectionOptions.schemaName,
message:
"Database schema: (You can pass multiple values separated by comma)",
name: "schema",
type: "input"
}
])
).schema;
}
options.connectionOptions.port = parseInt(answ.port, 10);
options.connectionOptions.host = answ.host;
@ -365,23 +369,27 @@ async function useInquirer(options: options): Promise<options> {
options.connectionOptions.databaseName = answ.dbName;
options.connectionOptions.ssl = answ.ssl;
} else {
options.connectionOptions.databaseName = (await inquirer.prompt([
options.connectionOptions.databaseName = (
await inquirer.prompt([
{
default: options.connectionOptions.databaseName,
message: "Path to database file:",
name: "dbName",
type: "input"
}
])
).dbName;
}
options.generationOptions.resultsPath = (
await inquirer.prompt([
{
default: options.connectionOptions.databaseName,
message: "Path to database file:",
name: "dbName",
default: options.generationOptions.resultsPath,
message: "Path where generated models should be stored:",
name: "output",
type: "input"
}
])).dbName;
}
options.generationOptions.resultsPath = (await inquirer.prompt([
{
default: options.generationOptions.resultsPath,
message: "Path where generated models should be stored:",
name: "output",
type: "input"
}
])).output;
])
).output;
const { customizeGeneration } = await inquirer.prompt([
{
default: false,
@ -391,78 +399,87 @@ async function useInquirer(options: options): Promise<options> {
}
]);
if (customizeGeneration) {
const customizations: string[] = (await inquirer.prompt([
{
choices: [
{
checked: !options.generationOptions.noConfigs,
name: "Generate config files",
value: "config"
},
{
name: "Generate lazy relations",
value: "lazy",
checked: options.generationOptions.lazy
},
{
name: "Use ActiveRecord syntax for generated models",
value: "activeRecord",
checked: options.generationOptions.activeRecord
},
{
name: "Use custom naming strategy",
value: "namingStrategy",
checked: !!options.generationOptions
.customNamingStrategyPath
},
{
name: "Generate RelationId fields",
value: "relationId",
checked: options.generationOptions.relationIds
},
{
name: "Omits schema identifier in generated entities",
value: "skipSchema",
checked: options.generationOptions.skipSchema
},
{
name:
"Generate constructor allowing partial initialization",
value: "constructor",
checked: options.generationOptions.generateConstructor
},
{
name: "Use specific naming convention",
value: "namingConvention",
checked: options.generationOptions.lazy
}
],
message: "Available customizations",
name: "selected",
type: "checkbox"
}
])).selected;
const customizations: string[] = (
await inquirer.prompt([
{
choices: [
{
checked: !options.generationOptions.noConfigs,
name: "Generate config files",
value: "config"
},
{
name: "Generate lazy relations",
value: "lazy",
checked: options.generationOptions.lazy
},
{
name:
"Use ActiveRecord syntax for generated models",
value: "activeRecord",
checked: options.generationOptions.activeRecord
},
{
name: "Use custom naming strategy",
value: "namingStrategy",
checked: !!options.generationOptions
.customNamingStrategyPath
},
{
name: "Generate RelationId fields",
value: "relationId",
checked: options.generationOptions.relationIds
},
{
name:
"Omits schema identifier in generated entities",
value: "skipSchema",
checked: options.generationOptions.skipSchema
},
{
name:
"Generate constructor allowing partial initialization",
value: "constructor",
checked:
options.generationOptions.generateConstructor
},
{
name: "Use specific naming convention",
value: "namingConvention",
checked: options.generationOptions.lazy
}
],
message: "Available customizations",
name: "selected",
type: "checkbox"
}
])
).selected;
options.generationOptions.propertyVisibility = (await inquirer.prompt([
{
choices: ["public", "protected", "private", "none"],
message:
"Defines which visibility should have the generated property",
name: "propertyVisibility",
default: options.generationOptions.propertyVisibility,
type: "list"
}
])).propertyVisibility;
options.generationOptions.propertyVisibility = (
await inquirer.prompt([
{
choices: ["public", "protected", "private", "none"],
message:
"Defines which visibility should have the generated property",
name: "propertyVisibility",
default: options.generationOptions.propertyVisibility,
type: "list"
}
])
).propertyVisibility;
options.generationOptions.strictMode = (await inquirer.prompt([
{
choices: ["none", "?", "!"],
message: "Mark fields as optional(?) or non-null(!)",
name: "strictMode",
default: options.generationOptions.strictMode,
type: "list"
}
])).strictMode;
options.generationOptions.strictMode = (
await inquirer.prompt([
{
choices: ["none", "?", "!"],
message: "Mark fields as optional(?) or non-null(!)",
name: "strictMode",
default: options.generationOptions.strictMode,
type: "list"
}
])
).strictMode;
options.generationOptions.noConfigs = !customizations.includes(
"config"
@ -482,21 +499,24 @@ async function useInquirer(options: options): Promise<options> {
);
if (customizations.includes("namingStrategy")) {
const namingStrategyPath = (await inquirer.prompt([
{
default: options.generationOptions.customNamingStrategyPath,
message: "Path to custom naming strategy file:",
name: "namingStrategy",
type: "input",
validate(value) {
const valid = value === "" || fs.existsSync(value);
return (
valid ||
"Please enter a a valid path to custom naming strategy file"
);
const namingStrategyPath = (
await inquirer.prompt([
{
default:
options.generationOptions.customNamingStrategyPath,
message: "Path to custom naming strategy file:",
name: "namingStrategy",
type: "input",
validate(value) {
const valid = value === "" || fs.existsSync(value);
return (
valid ||
"Please enter a a valid path to custom naming strategy file"
);
}
}
}
])).namingStrategy;
])
).namingStrategy;
if (namingStrategyPath && namingStrategyPath !== "") {
options.generationOptions.customNamingStrategyPath = namingStrategyPath;