Skip to content

Commit 8631f5a

Browse files
authored
feat(mssql)!: move mssql to the @sequelize/mssql package (#17206)
BREAKING CHANGE: Instead of installing the `mssql` package, users need to install `@sequelize/mssql`.
1 parent a90a4ee commit 8631f5a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+493
-281
lines changed

.github/workflows/ci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ jobs:
9292
run: yarn lerna run test-unit --scope=@sequelize/postgres
9393
- name: Unit tests (core - sqlite)
9494
run: yarn lerna run test-unit-sqlite --scope=@sequelize/core
95-
- name: Unit tests (mssql)
95+
- name: Unit tests (core - mssql)
9696
run: yarn lerna run test-unit-mssql --scope=@sequelize/core
97+
- name: Unit tests (mssql package)
98+
run: yarn lerna run test-unit --scope=@sequelize/mssql
9799
- name: Unit tests (core - db2)
98100
run: yarn lerna run test-unit-db2 --scope=@sequelize/core
99101
- name: Unit tests (core - ibmi)

.mocharc.json

-10
This file was deleted.

.mocharc.jsonc

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"require": "ts-node/register",
3+
"loader": "ts-node/esm",
4+
"extensions": ["js", "ts"],
5+
"watch-files": ["src"],
6+
"check-leaks": true,
7+
"timeout": 30000,
8+
"reporter": "spec",
9+
"exit": true,
10+
// Globals added as per https://github.com/sequelize/sequelize/pull/17206#discussion_r1538541573
11+
"globals": [
12+
"__extends",
13+
"__assign",
14+
"__rest",
15+
"__decorate",
16+
"__param",
17+
"__esDecorate",
18+
"__runInitializers",
19+
"__propKey",
20+
"__setFunctionName",
21+
"__metadata",
22+
"__awaiter",
23+
"__generator",
24+
"__exportStar",
25+
"__createBinding",
26+
"__values",
27+
"__read",
28+
"__spread",
29+
"__spreadArrays",
30+
"__spreadArray",
31+
"__await",
32+
"__asyncGenerator",
33+
"__asyncDelegator",
34+
"__asyncValues",
35+
"__makeTemplateObject",
36+
"__importStar",
37+
"__importDefault",
38+
"__classPrivateFieldGet",
39+
"__classPrivateFieldSet",
40+
"__classPrivateFieldIn",
41+
"__addDisposableResource",
42+
"__disposeResources"
43+
]
44+
}

.prettierrc.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,13 @@
33
"bracketSameLine": true,
44
"printWidth": 100,
55
"singleQuote": true,
6-
"arrowParens": "avoid"
6+
"arrowParens": "avoid",
7+
"overrides": [
8+
{
9+
"files": [".mocharc.jsonc"],
10+
"options": {
11+
"trailingComma": "none"
12+
}
13+
}
14+
]
715
}

nx.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
"$schema": "node_modules/nx/schemas/nx-schema.json",
33
"namedInputs": {
44
"default": ["{projectRoot}/**/*"],
5-
"prod": ["{projectRoot}/src/**/*", "{projectRoot}/package.json", "{projectRoot}/tsconfig.json"]
5+
"prod": [
6+
"{projectRoot}/src/**/*",
7+
"{projectRoot}/package.json",
8+
"{projectRoot}/tsconfig.json",
9+
"!{projectRoot}/src/**/*.test.ts"
10+
]
611
},
712
"targetDefaults": {
813
"build": {

packages/core/package.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,11 @@
100100
"rimraf": "5.0.5",
101101
"sinon": "17.0.1",
102102
"sinon-chai": "3.7.0",
103-
"snowflake-sdk": "1.10.0",
104-
"tedious": "18.1.0"
103+
"snowflake-sdk": "1.10.0"
105104
},
106105
"peerDependenciesMeta": {
107106
"snowflake-sdk": {
108107
"optional": true
109-
},
110-
"tedious": {
111-
"optional": true
112108
}
113109
},
114110
"keywords": [

packages/core/src/dialects/mssql/query.d.ts

-3
This file was deleted.

packages/core/src/errors/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,3 @@ export {
2828
ValidationErrorItemType,
2929
} from './validation-error';
3030
export { UniqueConstraintError } from './validation/unique-constraint-error';
31-
32-
export { AsyncQueueError } from '../dialects/mssql/async-queue';

packages/core/src/index.mjs

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export const BelongsToManyAssociation = Pkg.BelongsToManyAssociation;
5252
export const BaseError = Pkg.BaseError;
5353

5454
export const AggregateError = Pkg.AggregateError;
55-
export const AsyncQueueError = Pkg.AsyncQueueError;
5655
export const AssociationError = Pkg.AssociationError;
5756
export const BulkRecordError = Pkg.BulkRecordError;
5857
export const ConnectionError = Pkg.ConnectionError;

packages/core/src/sequelize.internals.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export function importDialect(dialect: DialectName): typeof AbstractDialect {
99
// eslint-disable-next-line import/no-extraneous-dependencies -- legacy function, will be removed. User needs to install the dependency themselves
1010
return require('@sequelize/mariadb').MariaDbDialect;
1111
case 'mssql':
12-
return require('./dialects/mssql').MsSqlDialect;
12+
// eslint-disable-next-line import/no-extraneous-dependencies -- legacy function, will be removed. User needs to install the dependency themselves
13+
return require('@sequelize/mssql').MsSqlDialect;
1314
case 'mysql':
1415
// eslint-disable-next-line import/no-extraneous-dependencies -- legacy function, will be removed. User needs to install the dependency themselves
1516
return require('@sequelize/mysql').MySqlDialect;

packages/core/test/integration/dialects/mssql/async-queue.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { AsyncQueueError, ConnectionError, DataTypes, Model } from '@sequelize/core';
2-
import type { MsSqlConnection } from '@sequelize/core/_non-semver-use-at-your-own-risk_/dialects/mssql/connection-manager.js';
1+
import { ConnectionError, DataTypes, Model } from '@sequelize/core';
32
import { Attribute, NotNull } from '@sequelize/core/decorators-legacy';
3+
import type { MsSqlConnection } from '@sequelize/mssql';
4+
import { AsyncQueueError } from '@sequelize/mssql';
45
import { expect } from 'chai';
56
import { beforeAll2, sequelize, setResetMode } from '../../support';
67

packages/core/test/unit/dialects/mssql/connection-manager.test.js

-111
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import type { Options } from '@sequelize/core';
2+
import { ConnectionError, Sequelize } from '@sequelize/core';
3+
import type { MsSqlDialect } from '@sequelize/mssql';
4+
import type { RequiredBy } from '@sequelize/utils';
5+
import { assert, expect } from 'chai';
6+
import sinon from 'sinon';
7+
import { Connection as TediousConnection } from 'tedious';
8+
import { getTestDialect } from '../../../support';
9+
10+
const dialect = getTestDialect();
11+
12+
type TestConnection = Omit<TediousConnection, 'once' | 'removeListener' | 'on'> & {
13+
once(event: string, cb: () => void): void;
14+
removeListener(): void;
15+
on(): void;
16+
};
17+
18+
describe('[MSSQL Specific] Connection Manager', () => {
19+
if (dialect !== 'mssql') {
20+
return;
21+
}
22+
23+
let config: RequiredBy<Options<MsSqlDialect>, 'dialectOptions'>;
24+
let instance: Sequelize<MsSqlDialect>;
25+
let Connection: Partial<TestConnection>;
26+
let connectionStub: sinon.SinonStub;
27+
28+
beforeEach(() => {
29+
config = {
30+
dialect: 'mssql',
31+
database: 'none',
32+
username: 'none',
33+
password: 'none',
34+
host: 'localhost',
35+
port: 2433,
36+
pool: {},
37+
dialectOptions: {
38+
domain: 'TEST.COM',
39+
},
40+
};
41+
instance = new Sequelize(config);
42+
Connection = {};
43+
// @ts-expect-error -- lib is private
44+
connectionStub = sinon.stub(instance.connectionManager, 'lib').value({
45+
Connection: function fakeConnection() {
46+
return Connection;
47+
},
48+
});
49+
});
50+
51+
afterEach(() => {
52+
connectionStub.restore();
53+
});
54+
55+
it('connectionManager._connect() does not delete `domain` from config.dialectOptions', async () => {
56+
Connection = {
57+
STATE: TediousConnection.prototype.STATE,
58+
state: undefined,
59+
once: (event, cb) => {
60+
if (event === 'connect') {
61+
setTimeout(() => {
62+
cb();
63+
}, 500);
64+
}
65+
},
66+
removeListener: () => {},
67+
on: () => {},
68+
};
69+
70+
expect(config.dialectOptions.domain).to.equal('TEST.COM');
71+
// @ts-expect-error -- protected method
72+
await instance.dialect.connectionManager._connect(config);
73+
expect(config.dialectOptions.domain).to.equal('TEST.COM');
74+
});
75+
76+
it('connectionManager._connect() should reject if end was called and connect was not', async () => {
77+
Connection = {
78+
STATE: TediousConnection.prototype.STATE,
79+
state: undefined,
80+
once(event, cb) {
81+
if (event === 'end') {
82+
setTimeout(() => {
83+
cb();
84+
}, 500);
85+
}
86+
},
87+
removeListener: () => {},
88+
on: () => {},
89+
};
90+
91+
try {
92+
// @ts-expect-error -- protected method
93+
await instance.dialect.connectionManager._connect(config);
94+
assert.fail('Expected an error to be thrown');
95+
} catch (error) {
96+
assert(error instanceof ConnectionError);
97+
expect(error.name).to.equal('SequelizeConnectionError');
98+
assert(error.cause instanceof Error);
99+
expect(error.cause.message).to.equal('Connection was closed by remote server');
100+
}
101+
});
102+
103+
it('connectionManager._connect() should call connect if state is initialized', async () => {
104+
const connectStub = sinon.stub();
105+
Connection = {
106+
STATE: TediousConnection.prototype.STATE,
107+
state: TediousConnection.prototype.STATE.INITIALIZED,
108+
connect: connectStub,
109+
once(event, cb) {
110+
if (event === 'connect') {
111+
setTimeout(() => {
112+
cb();
113+
}, 500);
114+
}
115+
},
116+
removeListener: () => {},
117+
on: () => {},
118+
};
119+
120+
// @ts-expect-error -- protected method
121+
await instance.dialect.connectionManager._connect(config);
122+
expect(connectStub.called).to.equal(true);
123+
});
124+
});

packages/core/test/unit/dialects/mssql/query-generator.test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ const Support = require('../../../support');
55
const expectsql = Support.expectsql;
66
const current = Support.sequelize;
77
const { DataTypes, Op } = require('@sequelize/core');
8-
const {
9-
MsSqlQueryGenerator: QueryGenerator,
10-
} = require('@sequelize/core/_non-semver-use-at-your-own-risk_/dialects/mssql/query-generator.js');
8+
const { MsSqlQueryGenerator: QueryGenerator } = require('@sequelize/mssql');
119

1210
if (current.dialect.name === 'mssql') {
1311
describe('[MSSQL Specific] QueryGenerator', () => {

0 commit comments

Comments
 (0)