Skip to content

Commit c1f42f1

Browse files
author
kukoo
committed
update @types/sequelize to 4.0.69, downgrade @types/bluebird to 3.5.4, update new v3/Sequelize constructor
1 parent f8a19de commit c1f42f1

File tree

5 files changed

+39
-42
lines changed

5 files changed

+39
-42
lines changed

lib/models/BaseSequelize.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ export abstract class BaseSequelize {
2222
thoughMap: { [through: string]: any } = {};
2323
_: { [modelName: string]: (typeof Model) } = {};
2424

25-
static isISequelizeConfig(obj: any): obj is ISequelizeConfig {
26-
return obj.hasOwnProperty("database") && obj.hasOwnProperty("username");
27-
}
28-
2925
static isISequelizeDbNameConfig(obj: any): obj is ISequelizeDbNameConfig {
3026
return obj.hasOwnProperty("name") && obj.hasOwnProperty("username");
3127
}
@@ -54,8 +50,7 @@ export abstract class BaseSequelize {
5450
}
5551

5652
if (BaseSequelize.isISequelizeDbNameConfig(config)) {
57-
// Sequelize uses "database" property as a database name.
58-
// @TODO: "name" property is deprecated, use "database" instead
53+
// @TODO: deprecate "name" property, use "database" instead
5954
const database = config.name;
6055
return {...config, database} as ISequelizeConfig;
6156
}

lib/models/v3/Sequelize.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
11
import 'reflect-metadata';
22
import * as SequelizeOrigin from 'sequelize';
33
import {Model} from "../Model";
4-
import {ISequelizeConfig} from "../../interfaces/ISequelizeConfig";
4+
import {SequelizeConfig} from "../../types/SequelizeConfig";
55
import {getModelName, getAttributes, getOptions} from "../../services/models";
66
import {PROPERTY_LINK_TO_ORIG} from "../../services/models";
77
import {BaseSequelize} from "../BaseSequelize";
88
import {Table} from "../../annotations/Table";
99
import {ISequelizeAssociation} from "../../interfaces/ISequelizeAssociation";
1010

11-
let preparedConfig;
12-
1311
export class Sequelize extends SequelizeOrigin implements BaseSequelize {
1412

1513
// to fix "$1" called with something that's not an instance of Sequelize.Model
1614
Model: any = Function;
1715

1816
thoughMap: { [through: string]: any } = {};
1917
_: { [modelName: string]: typeof Model } = {};
20-
init: (config: ISequelizeConfig) => void;
18+
init: (config: SequelizeConfig) => void;
2119
addModels: (models: Array<typeof Model> | string[]) => void;
2220
associateModels: (models: Array<typeof Model>) => void;
2321

24-
constructor(config: ISequelizeConfig) {
25-
// a spread operator would be the more reasonable approach here,
26-
// but this is currently not possible due to a bug by ts
27-
// https://github.com/Microsoft/TypeScript/issues/4130
28-
// TODO@robin probably make the constructor private and
29-
// TODO use a static factory function instead
22+
constructor(config: SequelizeConfig | string) {
23+
3024
super(
31-
(preparedConfig = BaseSequelize.prepareConfig(config), preparedConfig.name),
32-
preparedConfig.username,
33-
preparedConfig.password,
34-
preparedConfig
25+
(typeof config === "string") ?
26+
config : // URI string
27+
BaseSequelize.isISequelizeUriConfig(config) ?
28+
config.uri : // URI string from ISequelizeUriConfig
29+
BaseSequelize.prepareConfig(config) // Config object (ISequelizeConfig)
3530
);
3631

37-
this.init(config);
32+
if (BaseSequelize.isISequelizeUriConfig(config)) {
33+
this.options = {...this.options, ...config};
34+
}
35+
36+
if (typeof config !== "string") {
37+
this.init(config);
38+
}
3839
}
3940

4041
getThroughModel(through: string): typeof Model {

lib/models/v4/Sequelize.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {ISequelizeAssociation} from "../../interfaces/ISequelizeAssociation";
99

1010
export class Sequelize extends OriginSequelize implements BaseSequelize {
1111

12-
thoughMap: { [through: string]: any } = {};
13-
_: { [modelName: string]: typeof Model } = {};
12+
thoughMap: {[through: string]: any} = {};
13+
_: {[modelName: string]: typeof Model} = {};
1414
init: (config: SequelizeConfig) => void;
1515
addModels: (models: Array<typeof Model> | string[]) => void;
1616
associateModels: (models: Array<typeof Model>) => void;

package-lock.json

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232
"dependencies": {
3333
"@types/node": "6.0.41",
3434
"@types/reflect-metadata": "0.0.4",
35-
"@types/sequelize": "4.0.68",
35+
"@types/sequelize": "4.0.69",
3636
"es6-shim": "0.35.3"
3737
},
3838
"devDependencies": {
39+
"@types/bluebird": "3.5.4",
3940
"@types/chai": "3.4.35",
4041
"@types/chai-as-promised": "0.0.29",
4142
"@types/chai-datetime": "0.0.30",

0 commit comments

Comments
 (0)