From 67315b6fb078b8b27c89339c09094a303548d19f Mon Sep 17 00:00:00 2001 From: Oleksandr Podoprygora Date: Tue, 19 Jan 2016 21:31:21 +0200 Subject: [PATCH] exporting module to be able to declare variable of Umzug type like Umzug.Umzug --- umzug/umzug-tests.ts | 7 +- umzug/umzug.d.ts | 181 ++++++++++++++++++++++--------------------- 2 files changed, 95 insertions(+), 93 deletions(-) diff --git a/umzug/umzug-tests.ts b/umzug/umzug-tests.ts index 95d7521fd..fc3f5aea3 100644 --- a/umzug/umzug-tests.ts +++ b/umzug/umzug-tests.ts @@ -2,11 +2,12 @@ /// /// -import Umzug = require("umzug"); -import Sequelize = require("sequelize"); - +import * as Umzug from "umzug"; +import * as Sequelize from "sequelize"; +var someVar:Umzug.Umzug; var umzug = new Umzug({}); +someVar = umzug; umzug.up().then(function (result) { // do something with the result diff --git a/umzug/umzug.d.ts b/umzug/umzug.d.ts index 2e2b20a7c..82b66c6be 100644 --- a/umzug/umzug.d.ts +++ b/umzug/umzug.d.ts @@ -7,10 +7,11 @@ /// declare module "umzug" { + import Sequelize = require("sequelize"); - import Sequelize = require("sequelize"); + module umzug { - interface MigrationOptions { + interface MigrationOptions { /* * The params that gets passed to the migrations. @@ -30,9 +31,9 @@ declare module "umzug" { */ wrap?: ( fn : T ) => T; - } + } - interface JSONStorageOptions { + interface JSONStorageOptions { /** * The path to the json storage. @@ -40,55 +41,55 @@ declare module "umzug" { */ path?: string; - } + } - interface SequelizeStorageOptions { + interface SequelizeStorageOptions { - /** - * The configured instance of Sequelize. - * Optional if `model` is passed. - */ - sequelize?: Sequelize.Sequelize; + /** + * The configured instance of Sequelize. + * Optional if `model` is passed. + */ + sequelize?: Sequelize.Sequelize; - /** - * The to be used Sequelize model. - * Must have column name matching `columnName` option - * Optional of `sequelize` is passed. - */ - model?: Sequelize.Model; + /** + * The to be used Sequelize model. + * Must have column name matching `columnName` option + * Optional of `sequelize` is passed. + */ + model?: Sequelize.Model; - /** - * The name of the to be used model. - * Defaults to 'SequelizeMeta' - */ - modelName?: string; + /** + * The name of the to be used model. + * Defaults to 'SequelizeMeta' + */ + modelName?: string; - /** - * The name of table to create if `model` option is not supplied - * Defaults to `modelName` - */ - tableName?: string; + /** + * The name of table to create if `model` option is not supplied + * Defaults to `modelName` + */ + tableName?: string; - /** - * The name of table column holding migration name. - * Defaults to 'name'. - */ - columnName: string; + /** + * The name of table column holding migration name. + * Defaults to 'name'. + */ + columnName: string; - /** - * The type of the column holding migration name. - * Defaults to `Sequelize.STRING` - */ - columnType: Sequelize.DataTypeAbstract; + /** + * The type of the column holding migration name. + * Defaults to `Sequelize.STRING` + */ + columnType: Sequelize.DataTypeAbstract; - } + } - interface ExecuteOptions { + interface ExecuteOptions { migrations?: Array; method?: string; - } + } - interface UmzugOptions { + interface UmzugOptions { /** * The storage. @@ -122,67 +123,67 @@ declare module "umzug" { */ migrations? : MigrationOptions; - } + } - interface UpDownToOptions { + interface UpDownToOptions { - /** - * It is also possible to pass the name of a migration in order to - * just run the migrations from the current state to the passed - * migration name. - */ - to: string; + /** + * It is also possible to pass the name of a migration in order to + * just run the migrations from the current state to the passed + * migration name. + */ + to: string; - } + } - interface UpDownMigrationsOptions { + interface UpDownMigrationsOptions { - /** - * Running specific migrations while ignoring the right order, can be - * done like this: - */ - migrations: Array; + /** + * Running specific migrations while ignoring the right order, can be + * done like this: + */ + migrations: Array; - } + } - class Umzug { + interface Umzug { + /** + * The execute method is a general purpose function that runs for + * every specified migrations the respective function. + */ + execute(options? : ExecuteOptions) : Promise>; - constructor(options?: UmzugOptions); + /** + * You can get a list of pending/not yet executed migrations like this: + */ + pending() : Promise>; - /** - * The execute method is a general purpose function that runs for - * every specified migrations the respective function. - */ - execute(options? : ExecuteOptions) : Promise>; + /** + * You can get a list of already executed migrations like this: + */ + executed() : Promise>; - /** - * You can get a list of pending/not yet executed migrations like this: - */ - pending() : Promise>; + /** + * The up method can be used to execute all pending migrations. + */ + up(migration?: string) : Promise; + up(migrations?: Array) : Promise>; + up(options?: UpDownToOptions | UpDownMigrationsOptions ) : Promise>; - /** - * You can get a list of already executed migrations like this: - */ - executed() : Promise>; + /** + * The down method can be used to revert the last executed migration. + */ + down(migration?: string) : Promise; + down(migrations?: Array) : Promise>; + down(options?: UpDownToOptions | UpDownMigrationsOptions ) : Promise>; - /** - * The up method can be used to execute all pending migrations. - */ - up(migration?: string) : Promise; - up(migrations?: Array) : Promise>; - up(options?: UpDownToOptions | UpDownMigrationsOptions ) : Promise>; + } - /** - * The down method can be used to revert the last executed migration. - */ - down(migration?: string) : Promise; - down(migrations?: Array) : Promise>; - down(options?: UpDownToOptions | UpDownMigrationsOptions ) : Promise>; - - } - - var umzug : typeof Umzug; - - export = umzug; + interface UmzugStatic { + new (options?: UmzugOptions) : Umzug; + } + } + var umzug : umzug.UmzugStatic; + export = umzug; }