Skip to content

Commit

Permalink
fix: remove sequelize type dependency completely
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mmkal committed Oct 31, 2020
1 parent 07a1c1f commit 95314bf
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/storage/sequelize.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
import { UmzugStorage } from './contract';
import { SetRequired } from 'type-fest';
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
// @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)
import type { Sequelize as SequelizeType, Model as ModelClass } from 'sequelize';

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

type ModelClassType = typeof ModelClass & (new (values?: object, options?: any) => ModelTempInterface);
/**
* Minimal structure of a sequelize model, defined here to avoid a hard dependency.
* The type expected is `import { Model } from 'sequelize'`
*/
export interface ModelClass {
tableName: string;
sequelize?: SequelizeType;
getTableName(): string;
sync(): Promise<void>;
findAll(options?: {}): Promise<any[]>;
create(options: {}): Promise<void>;
destroy(options: {}): Promise<void>;
}

/**
* Minimal structure of a sequelize model, defined here to avoid a hard dependency.
* The type expected is `import { Sequelize } from 'sequelize'`
*/
export interface SequelizeType {
getQueryInterface(): any;
isDefined(modelName: string): boolean;
model(modelName: string): any;
define(modelName: string, columns: {}, options: {}): {};
}

type ModelClassType = ModelClass & (new (values?: object, options?: any) => ModelTempInterface);

interface _SequelizeStorageConstructorOptions {
/**
Expand Down

0 comments on commit 95314bf

Please sign in to comment.