Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
feat(sequelize): add typings
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrossmann committed Dec 6, 2018
1 parent 80f4f40 commit e981ce2
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/sequelize/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/sequelize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@atlas.js/errors": "^0.2.1",
"@atlas.js/hook": "^2.0.1",
"@atlas.js/service": "^1.1.1",
"@types/sequelize": "^4.27.32",
"sequelize": "^4.37.6",
"umzug": "^2.0.0"
},
Expand Down
26 changes: 26 additions & 0 deletions packages/sequelize/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Service from './service'
import ModelsHook from './models'
import RelationsHook from './relations'
import MigrationAction from './migration'
import {
Model,
DataTypes,
Deferrable,
Op,
} from 'sequelize'
import * as sequelize from 'sequelize'

declare module '@atlas.js/sequelize' {

export {
Service,
ModelsHook,
RelationsHook,
MigrationAction,
Op,
Model,
DataTypes,
Deferrable,
sequelize,
}
}
52 changes: 52 additions & 0 deletions packages/sequelize/src/migration.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Action from '@atlas.js/action'

/**
* This action allows you to programmatically execute migrations using the Umzug migrator.
*
* ## Usage:
*
* First, add this action to your Atlas instance, and then:
*
* `await atlas.actions.migration.up()`
* `await atlas.actions.migration.down()`
*
* You can also execute the action's methods from the Atlas CLI:
*
* `npx atlas exec migration up`
*
* @see https://www.npmjs.com/package/umzug
*/
declare class Migration extends Action {
/**
* Migrate upwards/apply
*
* @see https://www.npmjs.com/package/umzug#executing-pending-migrations
*/
up(options: { from?: string, to?: string, migrations?: string[] }): Promise<string[]>
up(migration: string): Promise<string[]>
up(migrations: string[]): Promise<string[]>

/**
* Migrate downwards/revert
*
* @see https://www.npmjs.com/package/umzug#reverting-executed-migration
*/
down(options: { to?: string | 0, migration?: string[] }): Promise<string[]>
down(migration: string): Promise<string[]>
down(migrations: string[]): Promise<string[]>

/** Get a list of all pending migrations */
pending(): Promise<string[]>
}

declare namespace Migration {
interface Config {
/**
* Module location, relative to `atlas.root`, from which to load migration files
* @default migration
*/
module: string
}
}

export default Migration
26 changes: 26 additions & 0 deletions packages/sequelize/src/models.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import AtlasHook from '@atlas.js/hook'
import * as sequelize from 'sequelize'

/**
* This hook allows you to import your Sequelize models from a particular module location into the
* sequelize service
*/
declare class ModelsHook extends AtlasHook {
/** Hook runtime configuration values */
config: ModelsHook.Config

afterPrepare(): void
}

declare namespace ModelsHook {
/** Configuration schema available to this hook */
interface Config {
/**
* Module location from which to load Sequelize models
* @default models
*/
module: string
}
}

export default ModelsHook
10 changes: 10 additions & 0 deletions packages/sequelize/src/relations.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import AtlasHook from '@atlas.js/hook'

/**
* This hook allows you to describe your model's associations (relations) directly on the model
*/
declare class RelationsHook extends AtlasHook {
afterPrepare(): void
}

export default RelationsHook
33 changes: 33 additions & 0 deletions packages/sequelize/src/service.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import AtlasService from '@atlas.js/service'
import * as sequelize from 'sequelize'

/**
* Use Sequelize ORM from within Atlas
*
* This service allows you to use Sequelize for connecting to various SQL databases
*/
declare class Service extends AtlasService {
/** Service runtime configuration values */
config: Service.Config

prepare(): Promise<sequelize.Sequelize>
start(service: sequelize.Sequelize): Promise<sequelize.Sequelize>
stop(service: sequelize.Sequelize): Promise<void>
}

declare namespace Service {
/** Configuration schema available to this service */
interface Config {
/**
* URI to connect to
* @default sqlite://atlas-db.sqlite
*/
uri?: string
/**
* Connection options
*/
options?: sequelize.Options
}
}

export default Service

0 comments on commit e981ce2

Please sign in to comment.