sequelize-typescript-generator 8.4.2 → 8.4.3

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.
@@ -23,6 +23,28 @@ jobs:
23
23
  - name: Install dependencies
24
24
  run: npm install
25
25
 
26
+ build:
27
+ runs-on: ubuntu-latest
28
+ needs: setup
29
+ steps:
30
+ - name: Check out repository code
31
+ uses: actions/checkout@v2
32
+
33
+ - name: Setup node
34
+ uses: actions/setup-node@v2
35
+ with:
36
+ node-version: '12'
37
+
38
+ - name: Restore node_modules
39
+ id: cache-node-modules
40
+ uses: actions/cache@v2
41
+ with:
42
+ path: node_modules
43
+ key: node-modules-${{ hashFiles('package-lock.json') }}
44
+
45
+ - name: Build
46
+ run: npm run build
47
+
26
48
  test_mysql:
27
49
  runs-on: ubuntu-latest
28
50
  needs: setup
@@ -76,7 +76,7 @@ class ModelBuilder extends Builder_1.Builder {
76
76
  };
77
77
  return props;
78
78
  };
79
- return ts.createProperty([
79
+ return ts.factory.createPropertyDeclaration([
80
80
  ...(col.foreignKey ?
81
81
  [(0, utils_1.generateArrowDecorator)(foreignKeyDecorator, [col.foreignKey.targetModel])]
82
82
  : []),
@@ -85,7 +85,7 @@ class ModelBuilder extends Builder_1.Builder {
85
85
  col.indices.map(index => (0, utils_1.generateObjectLiteralDecorator)('Index', buildIndexDecoratorProps(index)))
86
86
  : [])
87
87
  ], undefined, col.name, (col.autoIncrement || col.allowNull || col.defaultValue !== undefined) ?
88
- ts.createToken(ts.SyntaxKind.QuestionToken) : ts.createToken(ts.SyntaxKind.ExclamationToken), ts.createTypeReferenceNode((_a = dialect.mapDbTypeToJs(col.type)) !== null && _a !== void 0 ? _a : 'any', undefined), undefined);
88
+ ts.factory.createToken(ts.SyntaxKind.QuestionToken) : ts.factory.createToken(ts.SyntaxKind.ExclamationToken), ts.factory.createTypeReferenceNode((_a = dialect.mapDbTypeToJs(col.type)) !== null && _a !== void 0 ? _a : 'any', undefined), undefined);
89
89
  }
90
90
  /**
91
91
  * Build association class member
@@ -95,7 +95,7 @@ class ModelBuilder extends Builder_1.Builder {
95
95
  const { associationName, targetModel, joinModel } = association;
96
96
  const targetModels = [targetModel];
97
97
  joinModel && targetModels.push(joinModel);
98
- return ts.createProperty([
98
+ return ts.factory.createPropertyDeclaration([
99
99
  ...(association.sourceKey ?
100
100
  [
101
101
  (0, utils_1.generateArrowDecorator)(associationName, targetModels, { sourceKey: association.sourceKey })
@@ -104,9 +104,9 @@ class ModelBuilder extends Builder_1.Builder {
104
104
  (0, utils_1.generateArrowDecorator)(associationName, targetModels)
105
105
  ]),
106
106
  ], undefined, associationName.includes('Many') ?
107
- pluralize_1.default.plural(targetModel) : pluralize_1.default.singular(targetModel), ts.createToken(ts.SyntaxKind.QuestionToken), associationName.includes('Many') ?
108
- ts.createArrayTypeNode(ts.createTypeReferenceNode(targetModel, undefined)) :
109
- ts.createTypeReferenceNode(targetModel, undefined), undefined);
107
+ pluralize_1.default.plural(targetModel) : pluralize_1.default.singular(targetModel), ts.factory.createToken(ts.SyntaxKind.QuestionToken), associationName.includes('Many') ?
108
+ ts.factory.createArrayTypeNode(ts.factory.createTypeReferenceNode(targetModel, undefined)) :
109
+ ts.factory.createTypeReferenceNode(targetModel, undefined), undefined);
110
110
  }
111
111
  /**
112
112
  * Build table class declaration
@@ -148,41 +148,41 @@ class ModelBuilder extends Builder_1.Builder {
148
148
  const attributesInterfaceName = `${name}Attributes`;
149
149
  if (strict) {
150
150
  generatedCode += '\n';
151
- const attributesInterface = ts.createInterfaceDeclaration(undefined, [
152
- ts.createToken(ts.SyntaxKind.ExportKeyword),
153
- ], ts.createIdentifier(attributesInterfaceName), undefined, undefined, [
151
+ const attributesInterface = ts.factory.createInterfaceDeclaration(undefined, [
152
+ ts.factory.createToken(ts.SyntaxKind.ExportKeyword),
153
+ ], ts.factory.createIdentifier(attributesInterfaceName), undefined, undefined, [
154
154
  ...(Object.values(columns).map(c => {
155
155
  var _a;
156
- return ts.createPropertySignature(undefined, ts.createIdentifier(c.name), c.autoIncrement || c.allowNull || c.defaultValue !== undefined ?
157
- ts.createToken(ts.SyntaxKind.QuestionToken) : undefined, ts.createTypeReferenceNode((_a = dialect.mapDbTypeToJs(c.type)) !== null && _a !== void 0 ? _a : 'any', undefined));
156
+ return ts.factory.createPropertySignature(undefined, ts.factory.createIdentifier(c.name), c.autoIncrement || c.allowNull || c.defaultValue !== undefined ?
157
+ ts.factory.createToken(ts.SyntaxKind.QuestionToken) : undefined, ts.factory.createTypeReferenceNode((_a = dialect.mapDbTypeToJs(c.type)) !== null && _a !== void 0 ? _a : 'any', undefined));
158
158
  }))
159
159
  ]);
160
160
  generatedCode += (0, utils_1.nodeToString)(attributesInterface);
161
161
  generatedCode += '\n';
162
162
  }
163
- const classDecl = ts.createClassDeclaration([
163
+ const classDecl = ts.factory.createClassDeclaration([
164
164
  // @Table decorator
165
165
  (0, utils_1.generateObjectLiteralDecorator)('Table', {
166
166
  tableName: tableName,
167
167
  ...tableMetadata.schema && { schema: tableMetadata.schema },
168
168
  timestamps: tableMetadata.timestamps,
169
169
  ...tableMetadata.comment && { comment: tableMetadata.comment },
170
- })
170
+ }),
171
171
  ], [
172
- ts.createToken(ts.SyntaxKind.ExportKeyword),
172
+ ts.factory.createToken(ts.SyntaxKind.ExportKeyword),
173
173
  ], name, undefined, !strict ? [
174
- ts.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
175
- ts.createExpressionWithTypeArguments([], ts.createIdentifier('Model'))
174
+ ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
175
+ ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier('Model'), [])
176
176
  ])
177
177
  ] : [
178
- ts.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
179
- ts.createExpressionWithTypeArguments([
180
- ts.createTypeReferenceNode(ts.createIdentifier(attributesInterfaceName), undefined),
181
- ts.createTypeReferenceNode(ts.createIdentifier(attributesInterfaceName), undefined)
182
- ], ts.createIdentifier('Model'))
178
+ ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
179
+ ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier('Model'), [
180
+ ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(attributesInterfaceName), undefined),
181
+ ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(attributesInterfaceName), undefined)
182
+ ])
183
183
  ]),
184
- ts.createHeritageClause(ts.SyntaxKind.ImplementsKeyword, [
185
- ts.createExpressionWithTypeArguments(undefined, ts.createIdentifier(attributesInterfaceName))
184
+ ts.factory.createHeritageClause(ts.SyntaxKind.ImplementsKeyword, [
185
+ ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier(attributesInterfaceName), undefined)
186
186
  ])
187
187
  ],
188
188
  // Class members
@@ -48,12 +48,10 @@ exports.nodeToString = nodeToString;
48
48
  * @returns {string} Named import code
49
49
  */
50
50
  const generateNamedImports = (importsSpecifier, moduleSpecifier) => {
51
- return ts.createImportDeclaration(
52
- /* decorators */ undefined,
53
- /* modifiers */ undefined, ts.createImportClause(undefined, ts.createNamedImports([
51
+ return ts.factory.createImportDeclaration(undefined, undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports([
54
52
  ...importsSpecifier
55
- .map(is => ts.createImportSpecifier(false, undefined, ts.createIdentifier(is)))
56
- ])), ts.createLiteral(moduleSpecifier));
53
+ .map(is => ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier(is)))
54
+ ])), ts.factory.createStringLiteral(moduleSpecifier));
57
55
  };
58
56
  exports.generateNamedImports = generateNamedImports;
59
57
  /**
@@ -62,7 +60,7 @@ exports.generateNamedImports = generateNamedImports;
62
60
  * @returns {ts.ExportDeclaration}
63
61
  */
64
62
  const generateIndexExport = (modelFileName) => {
65
- return ts.createExportDeclaration([], undefined, undefined, ts.createLiteral(`./${modelFileName}`));
63
+ return ts.factory.createExportDeclaration(undefined, undefined, false, undefined, ts.factory.createStringLiteral(`./${modelFileName}`));
66
64
  };
67
65
  exports.generateIndexExport = generateIndexExport;
68
66
  /**
@@ -74,19 +72,33 @@ exports.generateIndexExport = generateIndexExport;
74
72
  const generateObjectLiteralDecorator = (decoratorIdentifier, props) => {
75
73
  const _createPropertyAssignment = (propName, propValue) => {
76
74
  let expression;
77
- if (typeof propValue === 'number') {
78
- expression = ts.createNumericLiteral(propValue);
75
+ switch (typeof propValue) {
76
+ case 'number':
77
+ expression = ts.factory.createNumericLiteral(propValue);
78
+ break;
79
+ case 'string':
80
+ if (propValue.startsWith('DataType.') || propValue.startsWith('Sequelize.')) {
81
+ expression = ts.factory.createIdentifier(propValue);
82
+ }
83
+ else {
84
+ expression = ts.factory.createStringLiteral(propValue);
85
+ }
86
+ break;
87
+ case 'boolean':
88
+ if (propValue) {
89
+ expression = ts.factory.createTrue();
90
+ }
91
+ else {
92
+ expression = ts.factory.createFalse();
93
+ }
94
+ break;
95
+ default:
96
+ expression = ts.factory.createIdentifier(propValue);
79
97
  }
80
- else if (typeof propValue === 'string' && (propValue.startsWith('DataType.') || propValue.startsWith('Sequelize.'))) {
81
- expression = ts.createIdentifier(propValue);
82
- }
83
- else {
84
- expression = ts.createLiteral(propValue);
85
- }
86
- return ts.createPropertyAssignment(propName, expression);
98
+ return ts.factory.createPropertyAssignment(propName, expression);
87
99
  };
88
- return ts.createDecorator(ts.createCall(ts.createIdentifier(decoratorIdentifier), undefined, [
89
- ts.createObjectLiteral([
100
+ return ts.factory.createDecorator(ts.factory.createCallExpression(ts.factory.createIdentifier(decoratorIdentifier), undefined, [
101
+ ts.factory.createObjectLiteralExpression([
90
102
  ...Object.entries(props)
91
103
  .map(e => _createPropertyAssignment(e[0], e[1]))
92
104
  ])
@@ -101,10 +113,10 @@ exports.generateObjectLiteralDecorator = generateObjectLiteralDecorator;
101
113
  * @returns {ts.Decorator}
102
114
  */
103
115
  const generateArrowDecorator = (decoratorIdentifier, arrowTargetIdentifiers, objectLiteralProps) => {
104
- const argumentsArray = arrowTargetIdentifiers.map(t => ts.createArrowFunction(undefined, undefined, [], undefined, ts.createToken(ts.SyntaxKind.EqualsGreaterThanToken), ts.createIdentifier(t)));
105
- objectLiteralProps && argumentsArray.push(ts.createObjectLiteral([
106
- ...Object.entries(objectLiteralProps).map(e => ts.createPropertyAssignment(e[0], ts.createLiteral(e[1])))
116
+ const argumentsArray = arrowTargetIdentifiers.map(t => ts.factory.createArrowFunction(undefined, undefined, [], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), ts.factory.createIdentifier(t)));
117
+ objectLiteralProps && argumentsArray.push(ts.factory.createObjectLiteralExpression([
118
+ ...Object.entries(objectLiteralProps).map(e => ts.factory.createPropertyAssignment(e[0], ts.createLiteral(e[1])))
107
119
  ]));
108
- return ts.createDecorator(ts.createCall(ts.createIdentifier(decoratorIdentifier), undefined, argumentsArray));
120
+ return ts.factory.createDecorator(ts.factory.createCallExpression(ts.factory.createIdentifier(decoratorIdentifier), undefined, argumentsArray));
109
121
  };
110
122
  exports.generateArrowDecorator = generateArrowDecorator;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sequelize-typescript-generator",
3
- "version": "8.4.2",
3
+ "version": "8.4.3",
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,34 +35,37 @@
35
35
  "homepage": "https://github.com/spinlud/sequelize-typescript-generator.git#readme",
36
36
  "devDependencies": {
37
37
  "@types/bluebird": "^3.5.36",
38
- "@types/jest": "^28.1.6",
39
- "@types/node": "^18.7.4",
38
+ "@types/jest": "^29.0.0",
39
+ "@types/node": "^18.7.14",
40
40
  "@types/pluralize": "0.0.29",
41
- "@types/validator": "^13.7.5",
42
- "@types/yargs": "^17.0.11",
41
+ "@types/validator": "^13.7.6",
42
+ "@types/yargs": "^17.0.12",
43
+ "jest": "^28.1.3",
43
44
  "mariadb": "^3.0.1",
44
45
  "mysql2": "^2.3.3",
45
- "pg": "^8.7.3",
46
+ "pg": "^8.8.0",
46
47
  "pg-hstore": "^2.3.4",
47
48
  "reflect-metadata": "^0.1.13",
48
49
  "sqlite3": "^5.0.11",
49
50
  "tedious": "^14.7.0",
50
51
  "ts-jest": "^28.0.8",
51
52
  "ts-node-dev": "^2.0.0",
52
- "typescript": "^4.7.4",
53
53
  "wkx": "^0.5.0"
54
54
  },
55
55
  "dependencies": {
56
- "@types/eslint": "^8.4.5",
57
- "@typescript-eslint/parser": "^5.33.0",
56
+ "@types/eslint": "^8.4.6",
57
+ "@typescript-eslint/parser": "^5.36.1",
58
58
  "change-case": "^4.1.2",
59
- "eslint": "^8.22.0",
60
- "jest": "^28.1.3",
59
+ "eslint": "^8.23.0",
61
60
  "pluralize": "^8.0.0",
62
- "sequelize": "^6.21.3",
61
+ "sequelize": "^6.21.4",
63
62
  "sequelize-typescript": "^2.1.3",
63
+ "typescript": ">=4.7.0 <=4.7.4",
64
64
  "yargs": "^17.5.1"
65
65
  },
66
+ "peerDependencies": {
67
+ "typescript": ">=4.7.0 <=4.7.4"
68
+ },
66
69
  "keywords": [
67
70
  "sequelize",
68
71
  "sequelize-typescript",