Skip to content

Commit 95314bf

Browse files
committed
fix: remove sequelize type dependency completely
ts-ignore comments are stripped from declaration files: microsoft/TypeScript#38628 It'd be possible to use some kind of codegen to add them back in, but it's easier and more correct to define what we need explicitly from the sequelize type definitions.
1 parent 07a1c1f commit 95314bf

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/storage/sequelize.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
import { UmzugStorage } from './contract';
22
import { SetRequired } from 'type-fest';
3-
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
4-
// @ts-ignore (Avoid type errors for non-sequelize users. Can't use ts-expect-error; this _won't_ be an error when sequelize is installed)
5-
import type { Sequelize as SequelizeType, Model as ModelClass } from 'sequelize';
63

74
interface ModelTempInterface extends ModelClass, Record<string, any> {}
85

9-
type ModelClassType = typeof ModelClass & (new (values?: object, options?: any) => ModelTempInterface);
6+
/**
7+
* Minimal structure of a sequelize model, defined here to avoid a hard dependency.
8+
* The type expected is `import { Model } from 'sequelize'`
9+
*/
10+
export interface ModelClass {
11+
tableName: string;
12+
sequelize?: SequelizeType;
13+
getTableName(): string;
14+
sync(): Promise<void>;
15+
findAll(options?: {}): Promise<any[]>;
16+
create(options: {}): Promise<void>;
17+
destroy(options: {}): Promise<void>;
18+
}
19+
20+
/**
21+
* Minimal structure of a sequelize model, defined here to avoid a hard dependency.
22+
* The type expected is `import { Sequelize } from 'sequelize'`
23+
*/
24+
export interface SequelizeType {
25+
getQueryInterface(): any;
26+
isDefined(modelName: string): boolean;
27+
model(modelName: string): any;
28+
define(modelName: string, columns: {}, options: {}): {};
29+
}
30+
31+
type ModelClassType = ModelClass & (new (values?: object, options?: any) => ModelTempInterface);
1032

1133
interface _SequelizeStorageConstructorOptions {
1234
/**

0 commit comments

Comments
 (0)