sequelize-typescript-generator 11.0.8 → 12.0.0

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.
@@ -11,6 +11,10 @@ class Builder {
11
11
  constructor(config, dialect) {
12
12
  this._config = config;
13
13
  this._dialect = dialect;
14
+ // Default Postgres schema if not provided
15
+ if (dialect.name === 'postgres' && !config.connection.schema) {
16
+ config.connection.schema = 'public';
17
+ }
14
18
  }
15
19
  get config() {
16
20
  return this._config;
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -42,10 +52,6 @@ const foreignKeyDecorator = 'ForeignKey';
42
52
  */
43
53
  class ModelBuilder extends Builder_1.Builder {
44
54
  constructor(config, dialect) {
45
- // Force 'public' schema on Postgres if not specified
46
- if (dialect.name === 'postgres' && config.metadata && !config.metadata.schema) {
47
- config.metadata.schema = 'public';
48
- }
49
55
  super(config, dialect);
50
56
  }
51
57
  /**
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.generateArrowDecorator = exports.generateObjectLiteralDecorator = exports.generateIndexExport = exports.generateNamedImports = exports.nodeToString = void 0;
27
37
  const ts = __importStar(require("typescript"));
@@ -11,7 +11,6 @@ export type TransformMap = {
11
11
  export type TransformFn = (value: string, target: TransformTarget) => string;
12
12
  export declare const TransformCases: Set<TransformCase>;
13
13
  export interface IConfigMetadata {
14
- schema?: 'public' | string;
15
14
  tables?: string[];
16
15
  skipTables?: string[];
17
16
  indices?: boolean;
@@ -19,17 +19,10 @@ class Dialect {
19
19
  * @returns {Promise<ITableMetadata[]>}
20
20
  */
21
21
  async buildTablesMetadata(config) {
22
- var _a, _b, _c, _d, _e, _f, _g, _h;
22
+ var _a, _b, _c, _d, _e, _f;
23
23
  let connection;
24
24
  const tablesMetadata = {};
25
25
  try {
26
- // Set schema for Postgres to 'public' if not provided
27
- if (config.connection.dialect === 'postgres' && !((_a = config.metadata) === null || _a === void 0 ? void 0 : _a.schema)) {
28
- config.metadata = {
29
- ...config.metadata,
30
- ...{ schema: 'public' },
31
- };
32
- }
33
26
  connection = (0, connection_1.createConnection)(config.connection);
34
27
  await connection.authenticate();
35
28
  let tables = await this.fetchTables(connection, config);
@@ -55,7 +48,7 @@ class Dialect {
55
48
  for (const { name: tableName, comment: tableComment } of tables) {
56
49
  const columnsMetadata = await this.fetchColumnsMetadata(connection, config, tableName);
57
50
  // Fetch indices metadata if required
58
- if ((_b = config.metadata) === null || _b === void 0 ? void 0 : _b.indices) {
51
+ if ((_a = config.metadata) === null || _a === void 0 ? void 0 : _a.indices) {
59
52
  for (const column of columnsMetadata) {
60
53
  column.indices = await this.fetchColumnIndexMetadata(connection, config, tableName, column.name);
61
54
  }
@@ -63,8 +56,8 @@ class Dialect {
63
56
  const tableMetadata = {
64
57
  originName: tableName,
65
58
  name: tableName,
66
- ...((_c = config.metadata) === null || _c === void 0 ? void 0 : _c.schema) && { schema: config.metadata.schema },
67
- timestamps: (_e = (_d = config.metadata) === null || _d === void 0 ? void 0 : _d.timestamps) !== null && _e !== void 0 ? _e : false,
59
+ schema: config.connection.schema,
60
+ timestamps: (_c = (_b = config.metadata) === null || _b === void 0 ? void 0 : _b.timestamps) !== null && _c !== void 0 ? _c : false,
68
61
  columns: {},
69
62
  comment: tableComment !== null && tableComment !== void 0 ? tableComment : undefined,
70
63
  };
@@ -82,8 +75,8 @@ class Dialect {
82
75
  connection && await connection.close();
83
76
  }
84
77
  // Apply associations if required
85
- if ((_f = config.metadata) === null || _f === void 0 ? void 0 : _f.associationsFile) {
86
- const parsedAssociations = AssociationsParser_1.AssociationsParser.parse((_g = config.metadata) === null || _g === void 0 ? void 0 : _g.associationsFile);
78
+ if ((_d = config.metadata) === null || _d === void 0 ? void 0 : _d.associationsFile) {
79
+ const parsedAssociations = AssociationsParser_1.AssociationsParser.parse((_e = config.metadata) === null || _e === void 0 ? void 0 : _e.associationsFile);
87
80
  for (const [tableName, association] of Object.entries(parsedAssociations)) {
88
81
  if (!tablesMetadata[tableName]) {
89
82
  console.warn('[WARNING]', `Associated table ${tableName} not found among (${Object.keys(tablesMetadata).join(', ')})`);
@@ -106,7 +99,7 @@ class Dialect {
106
99
  }
107
100
  }
108
101
  // Apply transformations if required
109
- if ((_h = config.metadata) === null || _h === void 0 ? void 0 : _h.case) {
102
+ if ((_f = config.metadata) === null || _f === void 0 ? void 0 : _f.case) {
110
103
  for (const [tableName, tableMetadata] of Object.entries(tablesMetadata)) {
111
104
  tablesMetadata[tableName] = (0, utils_1.caseTransformer)(tableMetadata, config.metadata.case);
112
105
  }
@@ -48,7 +48,7 @@ const jsDataTypesMap = {
48
48
  smallint: 'number',
49
49
  mediumint: 'number',
50
50
  tinyint: 'number',
51
- decimal: 'string',
51
+ decimal: 'number',
52
52
  float: 'number',
53
53
  double: 'number',
54
54
  int: 'number',
@@ -17,7 +17,7 @@ export declare class DialectPostgres extends Dialect {
17
17
  /**
18
18
  * Map database data type to javascript data type
19
19
  * @param {string} dbType
20
- * @returns {string
20
+ * @returns {string}
21
21
  */
22
22
  mapDbTypeToJs(dbType: string): string;
23
23
  /**
@@ -102,7 +102,7 @@ class DialectPostgres extends Dialect_1.Dialect {
102
102
  /**
103
103
  * Map database data type to javascript data type
104
104
  * @param {string} dbType
105
- * @returns {string
105
+ * @returns {string}
106
106
  */
107
107
  mapDbTypeToJs(dbType) {
108
108
  return jsDataTypesMap[dbType];
@@ -129,7 +129,7 @@ class DialectPostgres extends Dialect_1.Dialect {
129
129
  FROM information_schema.tables t
130
130
  JOIN pg_class pc
131
131
  ON t.table_name = pc.relname
132
- WHERE t.table_schema='${config.metadata.schema}' AND pc.relkind = 'r';
132
+ WHERE t.table_schema='${config.connection.schema}' AND pc.relkind = 'r';
133
133
  `;
134
134
  const tables = (await connection.query(query, {
135
135
  type: sequelize_1.QueryTypes.SELECT,
@@ -162,7 +162,7 @@ class DialectPostgres extends Dialect_1.Dialect {
162
162
  FROM pg_attribute a
163
163
  LEFT OUTER JOIN pg_index x
164
164
  ON a.attnum = ANY (x.indkey) AND a.attrelid = x.indrelid
165
- WHERE a.attrelid = '${config.metadata.schema}.\"${table}\"'::regclass AND a.attnum > 0
165
+ WHERE a.attrelid = '${config.connection.schema}.\"${table}\"'::regclass AND a.attnum > 0
166
166
  AND c.ordinal_position = a.attnum AND x.indisprimary IS TRUE
167
167
  ) AS is_primary,
168
168
  c.*,
@@ -188,11 +188,11 @@ class DialectPostgres extends Dialect_1.Dialect {
188
188
  ON (attrib.attnum = dep.refobjsubid AND attrib.attrelid = dep.refobjid)
189
189
  JOIN pg_namespace pn
190
190
  ON seqclass.relnamespace = pn.oid
191
- WHERE pn.nspname = '${config.metadata.schema}' AND depclass.relname = '${table}'
191
+ WHERE pn.nspname = '${config.connection.schema}' AND depclass.relname = '${table}'
192
192
  ) seq
193
193
  ON c.table_schema = seq.schema_name AND c.table_name = seq.table_name AND
194
194
  c.column_name = seq.column_name
195
- WHERE c.table_schema = '${config.metadata.schema}' AND c.table_name = '${table}'
195
+ WHERE c.table_schema = '${config.connection.schema}' AND c.table_name = '${table}'
196
196
  ORDER BY c.ordinal_position;
197
197
  `;
198
198
  const columns = await connection.query(query, {
@@ -214,7 +214,7 @@ class DialectPostgres extends Dialect_1.Dialect {
214
214
  this.mapDbTypeToSequelize(column.udt_name).key
215
215
  .split(' ')[0], // avoids 'DOUBLE PRECISION' key to include PRECISION in the mapping
216
216
  },
217
- allowNull: !!column.is_nullable && !column.is_primary,
217
+ allowNull: column.is_nullable === 'YES' && !column.is_primary,
218
218
  primaryKey: column.is_primary,
219
219
  autoIncrement: column.is_sequence,
220
220
  indices: [],
@@ -270,7 +270,7 @@ class DialectPostgres extends Dialect_1.Dialect {
270
270
  ON x.indexrelid = pc.oid
271
271
  INNER JOIN pg_am am
272
272
  ON pc.relam = am.oid
273
- WHERE a.attrelid = '${config.metadata.schema}.\"${table}\"'::regclass AND a.attnum > 0
273
+ WHERE a.attrelid = '${config.connection.schema}.\"${table}\"'::regclass AND a.attnum > 0
274
274
  AND a.attname = '${column}';
275
275
  `;
276
276
  const indices = await connection.query(query, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sequelize-typescript-generator",
3
- "version": "11.0.8",
3
+ "version": "12.0.0",
4
4
  "description": "Automatically generates typescript models compatible with sequelize-typescript library (https://www.npmjs.com/package/sequelize-typescript) directly from your source database.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -35,21 +35,21 @@
35
35
  "homepage": "https://github.com/spinlud/sequelize-typescript-generator.git#readme",
36
36
  "devDependencies": {
37
37
  "@types/bluebird": "^3.5.42",
38
- "@types/estree": "^1.0.5",
39
- "@types/jest": "^29.5.12",
38
+ "@types/estree": "^1.0.6",
39
+ "@types/jest": "^29.5.14",
40
40
  "@types/node": "^20.11.28",
41
41
  "@types/pluralize": "0.0.33",
42
- "@types/validator": "^13.11.9",
43
- "@types/yargs": "^17.0.32",
42
+ "@types/validator": "^13.12.2",
43
+ "@types/yargs": "^17.0.33",
44
44
  "jest": "^29.7.0",
45
- "mariadb": "^3.2.3",
46
- "mysql2": "^3.9.2",
47
- "pg": "^8.11.3",
45
+ "mariadb": "^3.4.0",
46
+ "mysql2": "^3.12.0",
47
+ "pg": "^8.13.1",
48
48
  "pg-hstore": "^2.3.4",
49
49
  "reflect-metadata": "^0.2.1",
50
50
  "sqlite3": "^5.1.7",
51
- "tedious": "^18.1.0",
52
- "ts-jest": "^29.1.2",
51
+ "tedious": "^18.6.1",
52
+ "ts-jest": "^29.2.5",
53
53
  "ts-node-dev": "^2.0.0",
54
54
  "wkx": "^0.5.0"
55
55
  },
@@ -59,9 +59,9 @@
59
59
  "change-case": "^4.1.2",
60
60
  "eslint": "^8.57.0",
61
61
  "pluralize": "^8.0.0",
62
- "sequelize": "^6.37.1",
62
+ "sequelize": "^6.37.5",
63
63
  "sequelize-typescript": "^2.1.6",
64
- "typescript": "^5.4.2",
64
+ "typescript": "^5.7.2",
65
65
  "yargs": "^17.7.2"
66
66
  },
67
67
  "peerDependencies": {