diff --git a/package.json b/package.json index 7b085ecf8..5aaa7751d 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "cross-env": "^7", "fs-jetpack": "^4", "sequelize": "^6", - "@sequelize/core": "^7.0.0-alpha.10", + "@sequelize/core": "^7.0.0-alpha.27", "sinon": "^13", "sinon-chai": "^3" }, @@ -52,6 +52,6 @@ "lodash": "^4.17.21", "sqlite3": "^5", "ts-node": "^10.4.0", - "typescript": "~4.5" + "typescript": "5.0" } } diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts deleted file mode 100644 index c90761b96..000000000 --- a/src/sscce-sequelize-6.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { DataTypes, Model } from 'sequelize'; -import { createSequelize6Instance } from '../setup/create-sequelize-instance'; -import { expect } from 'chai'; -import sinon from 'sinon'; - -// if your issue is dialect specific, remove the dialects you don't need to test on. -export const testingOnDialects = new Set(['mssql', 'sqlite', 'mysql', 'mariadb', 'postgres', 'postgres-native']); - -// You can delete this file if you don't want your SSCCE to be tested against Sequelize 6 - -// Your SSCCE goes inside this function. -export async function run() { - // This function should be used instead of `new Sequelize()`. - // It applies the config for your SSCCE to work on CI. - const sequelize = createSequelize6Instance({ - logQueryParameters: true, - benchmark: true, - define: { - // For less clutter in the SSCCE - timestamps: false, - }, - }); - - class Foo extends Model {} - - Foo.init({ - name: DataTypes.TEXT, - }, { - sequelize, - modelName: 'Foo', - }); - - // You can use sinon and chai assertions directly in your SSCCE. - const spy = sinon.spy(); - sequelize.afterBulkSync(() => spy()); - await sequelize.sync({ force: true }); - expect(spy).to.have.been.called; - - console.log(await Foo.create({ name: 'TS foo' })); - expect(await Foo.count()).to.equal(1); -} diff --git a/src/sscce-sequelize-7.ts b/src/sscce-sequelize-7.ts index 861b9fdea..f06ceb855 100644 --- a/src/sscce-sequelize-7.ts +++ b/src/sscce-sequelize-7.ts @@ -1,18 +1,39 @@ -import { DataTypes, Model } from '@sequelize/core'; -import { createSequelize7Instance } from '../setup/create-sequelize-instance'; -import { expect } from 'chai'; -import sinon from 'sinon'; +import { DataTypes, Model } from "@sequelize/core"; +import { createSequelize7Instance } from "../setup/create-sequelize-instance"; +import { Attribute } from "@sequelize/core/decorators-legacy"; +import type { Sequelize } from "@sequelize/core"; +import { expect } from "chai"; // if your issue is dialect specific, remove the dialects you don't need to test on. -export const testingOnDialects = new Set(['mssql', 'sqlite', 'mysql', 'mariadb', 'postgres', 'postgres-native']); +export const testingOnDialects = new Set([ + "mssql", + "sqlite", + "mysql", + "mariadb", + "postgres", + "postgres-native", +]); // You can delete this file if you don't want your SSCCE to be tested against Sequelize 7 +class User extends Model { + @Attribute({ + type: DataTypes.STRING, + allowNull: false, + }) + declare username: string; + + @Attribute({ + type: DataTypes.DATE, + allowNull: false, + }) + declare birthday: Date; +} // Your SSCCE goes inside this function. export async function run() { // This function should be used instead of `new Sequelize()`. // It applies the config for your SSCCE to work on CI. - const sequelize = createSequelize7Instance({ + let sequelize: Sequelize | undefined = createSequelize7Instance({ logQueryParameters: true, benchmark: true, define: { @@ -20,22 +41,42 @@ export async function run() { timestamps: false, }, }); + sequelize.addModels([User]); + await sequelize.sync({ force: true }); + + const jane = await User.create({ + username: "janedoe", + birthday: new Date(1980, 6, 20), + }); - class Foo extends Model {} + console.log("\nJane:", jane.toJSON()); - Foo.init({ - name: DataTypes.TEXT, - }, { - sequelize, - modelName: 'Foo', + await sequelize.close(); + sequelize = undefined; + + expect(jane.username).to.equal("janedoe"); + + const anotherSequelize = createSequelize7Instance({ + logQueryParameters: true, + benchmark: true, + define: { + // For less clutter in the SSCCE + timestamps: false, + }, }); - // You can use sinon and chai assertions directly in your SSCCE. - const spy = sinon.spy(); - sequelize.afterBulkSync(() => spy()); - await sequelize.sync({ force: true }); - expect(spy).to.have.been.called; + // Since the previous instance has been closed + // I expect that I can create another instance + // and associate the model to this instance + anotherSequelize.addModels([User]); + + const john = await User.create({ + username: "johndoe", + birthday: new Date(1990, 6, 20), + }); + console.log("John:", john.toJSON()); + + await anotherSequelize.close(); - console.log(await Foo.create({ name: 'TS foo' })); - expect(await Foo.count()).to.equal(1); + expect(john.username).to.equal("johndoe"); } diff --git a/tsconfig.json b/tsconfig.json index b17064f0e..2464dd4f0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,10 +5,11 @@ ], "compilerOptions": { "target": "es2021", - "module": "CommonJS", - "moduleResolution": "Node", + "module": "Node16", + "moduleResolution": "Node16", "esModuleInterop": true, "resolveJsonModule": true, + "experimentalDecorators": true, "newLine": "lf", "stripInternal": true, "strict": true,