From 32f83311f692751e8b6b89f0caecf2272193ad57 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 23 Jun 2019 15:49:45 -0700 Subject: [PATCH] chore: upgrade sequelize (#965) * 0.18.0 * chore: Upgrade sequelize 4 -> 5 * fix: migrations v5 support * fix: Majority of test failures * fix: the rest of v5 tests --- flow-typed/npm/sequelize_v4.x.x.js | 7446 ----------------- package.json | 6 +- server/api/__snapshots__/users.test.js.snap | 28 +- server/api/apiKeys.js | 2 +- server/api/auth.js | 2 +- server/api/collections.js | 20 +- server/api/documents.js | 44 +- server/api/documents.test.js | 9 +- server/api/hooks.js | 19 +- server/api/integrations.js | 2 +- server/api/notificationSettings.js | 4 +- server/api/shares.js | 11 +- server/api/shares.test.js | 7 +- server/api/team.js | 2 +- server/api/users.js | 16 +- server/api/views.js | 4 +- server/auth/index.js | 2 +- server/auth/slack.js | 6 +- server/commands/documentMover.js | 2 +- server/index.js | 2 +- server/logistics.js | 4 +- server/middlewares/authentication.js | 2 +- .../20170712055148-non-unique-email.js | 12 +- server/models/Document.js | 10 +- server/models/Team.js | 1 - server/models/User.js | 2 +- server/routes.js | 2 +- server/sequelize.js | 8 +- server/services/notifications.js | 6 +- server/services/slack.js | 4 +- server/services/websockets.js | 8 +- server/test/support.js | 30 +- server/utils/jwt.js | 2 +- server/utils/zip.js | 2 +- yarn.lock | 195 +- 35 files changed, 260 insertions(+), 7662 deletions(-) delete mode 100644 flow-typed/npm/sequelize_v4.x.x.js diff --git a/flow-typed/npm/sequelize_v4.x.x.js b/flow-typed/npm/sequelize_v4.x.x.js deleted file mode 100644 index 013d43b8..00000000 --- a/flow-typed/npm/sequelize_v4.x.x.js +++ /dev/null @@ -1,7446 +0,0 @@ -// flow-typed signature: 9b2cb7cedee72afe6d144951c88d49a5 -// flow-typed version: 03c38d65cd/sequelize_v4.x.x/flow_>=v0.42.x - -// @flow - -declare module "sequelize" { - /** - * The options for the getAssociation mixin of the belongsTo association. - * @see BelongsToGetOne - */ - declare export type BelongsToGetOneOptions = { - /** - * Apply a scope on the related model, or remove its default scope by passing false. - */ - scope?: ?(string | boolean) - } - - - /** - * The getAssociation mixin applied to models with belongsTo. - * An example of usage is as follows - - ```js - - User.belongsTo(Role); - - interface UserInstance extends Model, UserAttrib { - getRole: BelongsToGetOne; - // setRole... - // createRole... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to/ - * @see Model - */ - declare export type BelongsToGetOne> = { - /** - * Get the associated instance. - * @param options The options to use when getting the association. - */ - (options?: BelongsToGetOneOptions): Promise - } - - - /** - * The options for the setAssociation mixin of the belongsTo association. - * @see BelongsToSetOne - */ - declare export type BelongsToSetOneOptions = { - /** - * Skip saving this after setting the foreign key if false. - */ - save?: boolean - } - - - /** - * The setAssociation mixin applied to models with belongsTo. - * An example of usage is as follows: - - ```js - - User.belongsTo(Role); - - interface UserInstance extends Model, UserAttributes { - // getRole... - setRole: BelongsToSetOne; - // createRole... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to/ - * @see Model - */ - declare export type BelongsToSetOne, TInstancePrimaryKey> = { - /** - * Set the associated instance. - * @param newAssociation An instance or the primary key of an instance to associate with this. Pass null or undefined to remove the association. - * @param options the options passed to `this.save`. - */ - (newAssociation: ?(TInstance | TInstancePrimaryKey), options?: BelongsToSetOneOptions & InstanceSaveOptions): Promise - } - - /** - * The options for the createAssociation mixin of the belongsTo association. - * @see BelongsToCreateOne - */ - declare export type BelongsToCreateOneOptions = {} - - - /** - * The createAssociation mixin applied to models with belongsTo. - * An example of usage is as follows: - - ```js - - User.belongsTo(Role); - - interface UserInstance extends Model, UserAttributes { - // getRole... - // setRole... - createRole: BelongsToCreateOne; - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to/ - * @see Model - */ - declare export type BelongsToCreateOne = { - /** - * Create a new instance of the associated model and associate it with this. - * @param values The values used to create the association. - * @param options The options passed to `target.create` and `setAssociation`. - */ - (values?: TInitAttributes, options?: BelongsToCreateOneOptions & CreateOptions & BelongsToSetOneOptions): Promise - } - - - /** - * The options for the getAssociation mixin of the hasOne association. - * @see HasOneGetOne - */ - declare export type HasOneGetOneOptions = { - /** - * Apply a scope on the related model, or remove its default scope by passing false. - */ - scope?: ?(string | boolean) - } - - - /** - * The getAssociation mixin applied to models with hasOne. - * An example of usage is as follows: - - ```js - - User.hasOne(Role); - - interface UserInstance extends Model, UserAttrib { - getRole: HasOneGetOne; - // setRole... - // createRole... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/has-one/ - * @see Model - */ - declare export type HasOneGetOne> = { - /** - * Get the associated instance. - * @param options The options to use when getting the association. - */ - (options?: HasOneGetOneOptions): Promise - } - - - /** - * The options for the setAssociation mixin of the hasOne association. - * @see HasOneSetOne - */ - declare export type HasOneSetOneOptions = { - /** - * Skip saving this after setting the foreign key if false. - */ - save?: boolean - } - - - /** - * The setAssociation mixin applied to models with hasOne. - * An example of usage is as follows: - - ```js - - User.hasOne(Role); - - interface UserInstance extends Model, UserAttributes { - // getRole... - setRole: HasOneSetOne; - // createRole... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/has-one/ - * @see Model - */ - declare export type HasOneSetOne, TInstancePrimaryKey> = { - /** - * Set the associated instance. - * @param newAssociation An instance or the primary key of an instance to associate with this. Pass null or undefined to remove the association. - * @param options The options passed to `getAssocation` and `target.save`. - */ - (newAssociation: ?(TInstance | TInstancePrimaryKey), options?: HasOneSetOneOptions & HasOneGetOneOptions & InstanceSaveOptions): Promise - } - - - /** - * The options for the createAssociation mixin of the hasOne association. - * @see HasOneCreateOne - */ - declare export type HasOneCreateOneOptions = {} - - - /** - * The createAssociation mixin applied to models with hasOne. - * An example of usage is as follows: - - ```js - - User.hasOne(Role); - - interface UserInstance extends Model, UserAttributes { - // getRole... - // setRole... - createRole: HasOneCreateOne; - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/has-one/ - * @see Model - */ - declare export type HasOneCreateOne = { - /** - * Create a new instance of the associated model and associate it with this. - * @param values The values used to create the association. - * @param options The options passed to `target.create` and `setAssociation`. - */ - (values?: TInitAttributes, options?: HasOneCreateOneOptions & HasOneSetOneOptions & CreateOptions): Promise - } - - - /** - * The options for the getAssociations mixin of the hasMany association. - * @see HasManyGetMany - */ - declare export type HasManyGetManyOptions = { - /** - * An optional where clause to limit the associated models. - */ - where?: WhereOptions, - - /** - * Apply a scope on the related model, or remove its default scope by passing false. - */ - scope?: ?(string | boolean) - } - - - /** - * The getAssociations mixin applied to models with hasMany. - * An example of usage is as follows: - - ```js - - User.hasMany(Role); - - interface UserInstance extends Model, UserAttributes { - getRoles: HasManyGetMany; - // setRoles... - // addRoles... - // addRole... - // createRole... - // removeRole... - // removeRoles... - // hasRole... - // hasRoles... - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ - * @see Model - */ - declare export type HasManyGetMany> = { - /** - * Get everything currently associated with this, using an optional where clause. - * @param options The options to use when getting the associations. - */ - (options?: HasManyGetManyOptions): Promise - } - - - /** - * The options for the setAssociations mixin of the hasMany association. - * @see HasManySetMany - */ - declare export type HasManySetManyOptions = { - /** - * Run validation for the join model. - */ - validate?: boolean - } - - - /** - * The setAssociations mixin applied to models with hasMany. - * An example of usage is as follows: - - ```js - - User.hasMany(Role); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - setRoles: HasManySetMany; - // addRoles... - // addRole... - // createRole... - // removeRole... - // removeRoles... - // hasRole... - // hasRoles... - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ - * @see Model - */ - declare export type HasManySetMany, TInstancePrimaryKey> = { - /** - * Set the associated models by passing an array of instances or their primary keys. - * Everything that it not in the passed array will be un-associated. - * @param newAssociations An array of instances or primary key of instances to associate with this. Pass null or undefined to remove all associations. - * @param options The options passed to `target.findAll` and `update`. - */ - (newAssociations: ?$ReadOnlyArray, options?: HasManySetManyOptions & AnyFindOptions & InstanceUpdateOptions): Promise - } - - - /** - * The options for the addAssociations mixin of the hasMany association. - * @see HasManyAddMany - */ - declare export type HasManyAddManyOptions = { - /** - * Run validation for the join model. - */ - validate?: boolean - } - - - /** - * The addAssociations mixin applied to models with hasMany. - * An example of usage is as follows: - - ```js - - User.hasMany(Role); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - // setRoles... - addRoles: HasManyAddMany; - // addRole... - // createRole... - // removeRole... - // removeRoles... - // hasRole... - // hasRoles... - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ - * @see Model - */ - declare export type HasManyAddMany, TInstancePrimaryKey> ={ - /** - * Associate several instances with this. - * @param newAssociations An array of instances or primary key of instances to associate with this. - * @param options The options passed to `target.update`. - */ - (newAssociations: $ReadOnlyArray, options?: HasManyAddManyOptions & InstanceUpdateOptions): Promise - } - - - /** - * The options for the addAssociation mixin of the hasMany association. - * @see HasManyAddOne - */ - declare export type HasManyAddOneOptions = { - /** - * Run validation for the join model. - */ - validate?: boolean - } - - - /** - * The addAssociation mixin applied to models with hasMany. - * An example of usage is as follows: - - ```js - - User.hasMany(Role); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - // setRoles... - // addRoles... - addRole: HasManyAddOne; - // createRole... - // removeRole... - // removeRoles... - // hasRole... - // hasRoles... - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ - * @see Model - */ - declare export type HasManyAddOne, TInstancePrimaryKey> = { - /** - * Associate an instance with this. - * @param newAssociation An instance or the primary key of an instance to associate with this. - * @param options The options passed to `target.update`. - */ - (newAssociation: TInstance | TInstancePrimaryKey, options?: HasManyAddOneOptions & InstanceUpdateOptions): Promise - } - - - /** - * The options for the createAssociation mixin of the hasMany association. - * @see HasManyCreateOne - */ - declare export type HasManyCreateOneOptions = {} - - - /** - * The createAssociation mixin applied to models with hasMany. - * An example of usage is as follows: - - ```js - - User.hasMany(Role); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - // setRoles... - // addRoles... - // addRole... - createRole: HasManyCreateOne; - // removeRole... - // removeRoles... - // hasRole... - // hasRoles... - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ - * @see Model - */ - declare export type HasManyCreateOne> = { - /** - * Create a new instance of the associated model and associate it with this. - * @param values The values used to create the association. - * @param options The options to use when creating the association. - */ - (values?: TInitAttributes, options?: HasManyCreateOneOptions & CreateOptions): Promise - } - - - /** - * The options for the removeAssociation mixin of the hasMany association. - * @see HasManyRemoveOne - */ - declare export type HasManyRemoveOneOptions = {} - - - /** - * The removeAssociation mixin applied to models with hasMany. - * An example of usage is as follows: - - ```js - - User.hasMany(Role); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - // setRoles... - // addRoles... - // addRole... - // createRole... - removeRole: HasManyRemoveOne; - // removeRoles... - // hasRole... - // hasRoles... - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ - * @see Model - */ - declare export type HasManyRemoveOne, TInstancePrimaryKey> = { - /** - * Un-associate the instance. - * @param oldAssociated The instance or the primary key of the instance to un-associate. - * @param options The options passed to `target.update`. - */ - (oldAssociated: TInstance | TInstancePrimaryKey, options?: HasManyRemoveOneOptions & InstanceUpdateOptions): Promise - } - - - /** - * The options for the removeAssociations mixin of the hasMany association. - * @see HasManyRemoveMany - */ - declare export type HasManyRemoveManyOptions = {} - - - /** - * The removeAssociations mixin applied to models with hasMany. - * An example of usage is as follows: - - ```js - - User.hasMany(Role); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - // setRoles... - // addRoles... - // addRole... - // createRole... - // removeRole... - removeRoles: HasManyRemoveMany; - // hasRole... - // hasRoles... - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ - * @see Model - */ - declare export type HasManyRemoveMany, TInstancePrimaryKey> = { - /** - * Un-associate several instances. - * @param oldAssociated An array of instances or primary key of instances to un-associate. - * @param options The options passed to `target.update`. - */ - (oldAssociateds?: $ReadOnlyArray, options?: HasManyRemoveManyOptions & InstanceUpdateOptions): Promise - } - - - /** - * The options for the hasAssociation mixin of the hasMany association. - * @see HasManyHasOne - */ - declare export type HasManyHasOneOptions = {} - - - /** - * The hasAssociation mixin applied to models with hasMany. - * An example of usage is as follows: - - ```js - - User.hasMany(Role); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - // setRoles... - // addRoles... - // addRole... - // createRole... - // removeRole... - // removeRoles... - hasRole: HasManyHasOne; - // hasRoles... - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ - * @see Model - */ - declare export type HasManyHasOne, TInstancePrimaryKey> = { - /** - * Check if an instance is associated with this. - * @param target The instance or the primary key of the instance to check. - * @param options The options passed to `getAssociations`. - */ - (target: TInstance | TInstancePrimaryKey, options?: HasManyHasOneOptions & HasManyGetManyOptions): Promise - } - - - /** - * The options for the hasAssociations mixin of the hasMany association. - * @see HasManyHasMany - */ - declare export type HasManyHasManyOptions = {} - - - /** - * The removeAssociations mixin applied to models with hasMany. - * An example of usage is as follows: - - ```js - - User.hasMany(Role); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - // setRoles... - // addRoles... - // addRole... - // createRole... - // removeRole... - // removeRoles - // hasRole... - hasRoles: HasManyHasMany; - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ - * @see Model - */ - declare export type HasManyHasMany, TInstancePrimaryKey> = { - /** - * Check if all instances are associated with this. - * @param targets An array of instances or primary key of instances to check. - * @param options The options passed to `getAssociations`. - */ - (targets: $ReadOnlyArray, options?: HasManyHasManyOptions & HasManyGetManyOptions): Promise - } - - - /** - * The options for the countAssociations mixin of the hasMany association. - * @see HasManyCount - */ - declare export type HasManyCountOptions = { - /** - * An optional where clause to limit the associated models. - */ - where?: WhereOptions, - - /** - * Apply a scope on the related model, or remove its default scope by passing false. - */ - scope?: ?(string | boolean) - } - - - /** - * The countAssociations mixin applied to models with hasMany. - * An example of usage is as follows: - - ```js - - User.hasMany(Role); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - // setRoles... - // addRoles... - // addRole... - // createRole... - // removeRole... - // removeRoles... - // hasRole... - // hasRoles... - countRoles: HasManyCount; - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/ - * @see Model - */ - declare export type HasManyCount = { - /** - * Count everything currently associated with this, using an optional where clause. - * @param options The options to use when counting the associations. - */ - (options?: HasManyCountOptions): Promise - } - - - /** - * The options for the getAssociations mixin of the belongsToMany association. - * @see BelongsToManyGetMany - */ - declare export type BelongsToManyGetManyOptions = { - /** - * An optional where clause to limit the associated models. - */ - where?: WhereOptions, - - /** - * Apply a scope on the related model, or remove its default scope by passing false. - */ - scope?: ?(string | boolean) - } - - - /** - * The getAssociations mixin applied to models with belongsToMany. - * An example of usage is as follows: - - ```js - - User.belongsToMany(Role, { through: UserRole }); - - interface UserInstance extends Model, UserAttributes { - getRoles: BelongsToManyGetMany; - // setRoles... - // addRoles... - // addRole... - // createRole... - // removeRole... - // removeRoles... - // hasRole... - // hasRoles... - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/ - * @see Model - */ - declare export type BelongsToManyGetMany> = { - /** - * Get everything currently associated with this, using an optional where clause. - * @param options The options to use when getting the associations. - */ - (options?: BelongsToManyGetManyOptions): Promise - } - - - /** - * The options for the setAssociations mixin of the belongsToMany association. - * @see BelongsToManySetMany - */ - declare export type BelongsToManySetManyOptions = { - /** - * Run validation for the join model. - */ - validate?: boolean - } - - - /** - * The setAssociations mixin applied to models with belongsToMany. - * An example of usage is as follows: - - ```js - - User.belongsToMany(Role, { through: UserRole }); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - setRoles: BelongsToManySetMany; - // addRoles... - // addRole... - // createRole... - // removeRole... - // removeRoles... - // hasRole... - // hasRoles... - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/ - * @see Model - */ - declare export type BelongsToManySetMany, TInstancePrimaryKey, TJoinTableAttributes> = { - /** - * Set the associated models by passing an array of instances or their primary keys. - * Everything that it not in the passed array will be un-associated. - * @param newAssociations An array of instances or primary key of instances to associate with this. Pass null or undefined to remove all associations. - * @param options The options passed to `through.findAll`, `bulkCreate`, `update` and `destroy`. Can also hold additional attributes for the join table. - */ - (newAssociations: ?($ReadOnlyArray), options?: BelongsToManySetManyOptions & - AnyFindOptions & - BulkCreateOptions & - InstanceUpdateOptions & - InstanceDestroyOptions & - { - through?: TJoinTableAttributes - }): Promise - } - - - /** - * The options for the addAssociations mixin of the belongsToMany association. - * @see BelongsToManyAddMany - */ - declare export type BelongsToManyAddManyOptions = { - /** - * Run validation for the join model. - */ - validate?: boolean - } - - - /** - * The addAssociations mixin applied to models with belongsToMany. - * An example of usage is as follows: - - ```js - - User.belongsToMany(Role, { through: UserRole }); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - // setRoles... - addRoles: BelongsToManyAddMany; - // addRole... - // createRole... - // removeRole... - // removeRoles... - // hasRole... - // hasRoles... - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/ - * @see Model - */ - declare export type BelongsToManyAddMany, TInstancePrimaryKey, TJoinTableAttributes> = { - /** - * Associate several instances with this. - * @param newAssociations An array of instances or primary key of instances to associate with this. - * @param options The options passed to `through.findAll`, `bulkCreate`, `update` and `destroy`. Can also hold additional attributes for the join table. - */ - (newAssociations: $ReadOnlyArray, options?: BelongsToManyAddManyOptions & - AnyFindOptions & - BulkCreateOptions & - InstanceUpdateOptions & - InstanceDestroyOptions & - { - through?: TJoinTableAttributes - }): Promise - } - - - /** - * The options for the addAssociation mixin of the belongsToMany association. - * @see BelongsToManyAddOne - */ - declare export type BelongsToManyAddOneOptions = { - /** - * Run validation for the join model. - */ - validate?: boolean - } - - - /** - * The addAssociation mixin applied to models with belongsToMany. - * An example of usage is as follows: - - ```js - - User.belongsToMany(Role, { through: UserRole }); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - // setRoles... - // addRoles... - addRole: BelongsToManyAddOne; - // createRole... - // removeRole... - // removeRoles... - // hasRole... - // hasRoles... - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/ - * @see Model - */ - declare export type BelongsToManyAddOne, TInstancePrimaryKey, TJoinTableAttributes> = { - /** - * Associate an instance with this. - * @param newAssociation An instance or the primary key of an instance to associate with this. - * @param options The options passed to `through.findAll`, `bulkCreate`, `update` and `destroy`. Can also hold additional attributes for the join table. - */ - (newAssociation: TInstance | TInstancePrimaryKey, options?: BelongsToManyAddOneOptions & - AnyFindOptions & - BulkCreateOptions & - InstanceUpdateOptions & - InstanceDestroyOptions & - { - through?: TJoinTableAttributes - }): Promise - } - - - /** - * The options for the createAssociation mixin of the belongsToMany association. - * @see BelongsToManyCreateOne - */ - declare export type BelongsToManyCreateOneOptions = {} - - - /** - * The createAssociation mixin applied to models with belongsToMany. - * An example of usage is as follows: - - ```js - - User.belongsToMany(Role, { through: UserRole }); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - // setRoles... - // addRoles... - // addRole... - createRole: BelongsToManyCreateOne; - // removeRole... - // removeRoles... - // hasRole... - // hasRoles... - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/ - * @see Model - */ - declare export type BelongsToManyCreateOne, TJoinTableAttributes> = { - /** - * Create a new instance of the associated model and associate it with this. - * @param values The values used to create the association. - * @param options Options passed to `create` and `add`. Can also hold additional attributes for the join table. - */ - (values?: TInitAttributes, options?: BelongsToManyCreateOneOptions & CreateOptions & { - through?: TJoinTableAttributes - }): Promise - } - - - /** - * The options for the removeAssociation mixin of the belongsToMany association. - * @see BelongsToManyRemoveOne - */ - declare export type BelongsToManyRemoveOneOptions = {} - - - /** - * The removeAssociation mixin applied to models with belongsToMany. - * An example of usage is as follows: - - ```js - - User.belongsToMany(Role, { through: UserRole }); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - // setRoles... - // addRoles... - // addRole... - // createRole... - removeRole: BelongsToManyRemoveOne; - // removeRoles... - // hasRole... - // hasRoles... - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/ - * @see Model - */ - declare export type BelongsToManyRemoveOne, TInstancePrimaryKey> = { - /** - * Un-associate the instance. - * @param oldAssociated The instance or the primary key of the instance to un-associate. - * @param options The options passed to `through.destroy`. - */ - (oldAssociated: TInstance | TInstancePrimaryKey, options?: BelongsToManyRemoveOneOptions & InstanceDestroyOptions): Promise - } - - - /** - * The options for the removeAssociations mixin of the belongsToMany association. - * @see BelongsToManyRemoveMany - */ - declare export type BelongsToManyRemoveManyOptions = {} - - - /** - * The removeAssociations mixin applied to models with belongsToMany. - * An example of usage is as follows: - - ```js - - User.belongsToMany(Role, { through: UserRole }); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - // setRoles... - // addRoles... - // addRole... - // createRole... - // removeRole... - removeRoles: BelongsToManyRemoveMany; - // hasRole... - // hasRoles... - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/ - * @see Model - */ - declare export type BelongsToManyRemoveMany, TInstancePrimaryKey> = { - /** - * Un-associate several instances. - * @param oldAssociated An array of instances or primary key of instances to un-associate. - * @param options The options passed to `through.destroy`. - */ - (oldAssociateds?: $ReadOnlyArray, options?: BelongsToManyRemoveManyOptions & InstanceDestroyOptions): Promise - } - - - /** - * The options for the hasAssociation mixin of the belongsToMany association. - * @see BelongsToManyHasOne - */ - declare export type BelongsToManyHasOneOptions = {} - - - /** - * The hasAssociation mixin applied to models with belongsToMany. - * An example of usage is as follows: - - ```js - - User.belongsToMany(Role, { through: UserRole }); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - // setRoles... - // addRoles... - // addRole... - // createRole... - // removeRole... - // removeRoles... - hasRole: BelongsToManyHasOne; - // hasRoles... - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/ - * @see Model - */ - declare export type BelongsToManyHasOne, TInstancePrimaryKey> = { - /** - * Check if an instance is associated with this. - * @param target The instance or the primary key of the instance to check. - * @param options The options passed to `getAssociations`. - */ - (target: TInstance | TInstancePrimaryKey, options?: BelongsToManyHasOneOptions & BelongsToManyGetManyOptions): Promise - } - - - /** - * The options for the hasAssociations mixin of the belongsToMany association. - * @see BelongsToManyHasMany - */ - declare export type BelongsToManyHasManyOptions = {} - - - /** - * The removeAssociations mixin applied to models with belongsToMany. - * An example of usage is as follows: - - ```js - - User.belongsToMany(Role, { through: UserRole }); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - // setRoles... - // addRoles... - // addRole... - // createRole... - // removeRole... - // removeRoles - // hasRole... - hasRoles: BelongsToManyHasMany; - // countRoles... - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/ - * @see Model - */ - declare export type BelongsToManyHasMany, TInstancePrimaryKey> = { - /** - * Check if all instances are associated with this. - * @param targets An array of instances or primary key of instances to check. - * @param options The options passed to `getAssociations`. - */ - (targets: $ReadOnlyArray, options?: BelongsToManyHasManyOptions & BelongsToManyGetManyOptions): Promise - } - - - /** - * The options for the countAssociations mixin of the belongsToMany association. - * @see BelongsToManyCount - */ - declare export type BelongsToManyCountOptions = { - /** - * An optional where clause to limit the associated models. - */ - where?: WhereOptions, - - /** - * Apply a scope on the related model, or remove its default scope by passing false. - */ - scope?: ?(string | boolean) - } - - - /** - * The countAssociations mixin applied to models with belongsToMany. - * An example of usage is as follows: - - ```js - - User.belongsToMany(Role, { through: UserRole }); - - interface UserInstance extends Model, UserAttributes { - // getRoles... - // setRoles... - // addRoles... - // addRole... - // createRole... - // removeRole... - // removeRoles... - // hasRole... - // hasRoles... - countRoles: BelongsToManyCount; - } - ``` - * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/ - * @see Model - */ - declare export type BelongsToManyCount = { - /** - * Count everything currently associated with this, using an optional where clause. - * @param options The options to use when counting the associations. - */ - (options?: BelongsToManyCountOptions): Promise - } - - - /** - * Foreign Key Options - * @see AssociationOptions - */ - declare export type AssociationForeignKeyOptions = ColumnOptions & { - /** - * Attribute name for the relation - */ - name?: string - } - - - - /** - * Options provided when associating models - * @see Association class - */ - declare export type AssociationOptions = { - /** - * Set to true to run before-/afterDestroy hooks when an associated model is deleted because of a cascade. - * For example if `User.hasOne(Profile, {onDelete: 'cascade', hooks:true})`, the before-/afterDestroy hooks - for profile will be called when a user is deleted. Otherwise the profile will be deleted without invoking - any hooks. - - Defaults to false - */ - hooks?: boolean, - - /** - * The alias of this model, in singular form. See also the `name` option passed to `sequelize.define`. If - * you create multiple associations between the same tables, you should provide an alias to be able to - distinguish between them. If you provide an alias when creating the assocition, you should provide the - same alias when eager loading and when getting assocated models. Defaults to the singularized name of - target - */ - as?: string | { - singular: string, - plural: string - }, - - /** - * The name of the foreign key in the target table or an object representing the type definition for the - * foreign column (see `Sequelize.define` for syntax). When using an object, you can add a `name` property - to set the name of the column. Defaults to the name of source + primary key of source - */ - foreignKey?: string | AssociationForeignKeyOptions, - - /** - * What happens when delete occurs. - * - Cascade if this is a n:m, and set null if it is a 1:m - - Defaults to 'SET_NULL' or 'CASCADE' - */ - onDelete?: string, - - /** - * What happens when update occurs - * - Defaults to 'CASCADE' - */ - onUpdate?: string, - - /** - * Should on update and on delete constraints be enabled on the foreign key. - */ - constraints?: boolean, - foreignKeyConstraint?: boolean - } - - - /** - * Options for Association Scope - * @see AssociationOptionsManyToMany - */ - declare export type AssociationScope = { - [scopeName: string]: any - } - - - /** - * Options provided for many-to-many relationships - * @see AssociationOptionsHasMany - * @see AssociationOptionsBelongsToMany - */ - declare export type AssociationOptionsManyToMany = AssociationOptions & { - /** - * A key/value set that will be used for association create and find defaults on the target. - * (sqlite not supported for N:M) - */ - scope?: ?AssociationScope - } - - - - /** - * Options provided when associating models with hasOne relationship - * @see Association class hasOne method - */ - declare export type AssociationOptionsHasOne = AssociationOptions & { - /** - * A string or a data type to represent the identifier in the table - */ - keyType?: DataTypeAbstract - } - - - - /** - * Options provided when associating models with belongsTo relationship - * @see Association class belongsTo method - */ - declare export type AssociationOptionsBelongsTo = AssociationOptions & { - /** - * The name of the field to use as the key for the association in the target table. Defaults to the primary - * key of the target table - */ - targetKey?: string, - - /** - * A string or a data type to represent the identifier in the table - */ - keyType?: DataTypeAbstract - } - - - - /** - * Options provided when associating models with hasMany relationship - * @see Association class hasMany method - */ - declare export type AssociationOptionsHasMany = AssociationOptionsManyToMany & { - /** - * A string or a data type to represent the identifier in the table - */ - keyType?: DataTypeAbstract - } - - - - /** - * Options provided when associating models with belongsToMany relationship - * @see Association class belongsToMany method - */ - declare export type AssociationOptionsBelongsToMany> = AssociationOptionsManyToMany & { - /** - * The name of the table that is used to join source and target in n:m associations. Can also be a - * sequelize - model if you want to define the junction table yourself and add extra attributes to it. - - In 3.4.1 version of Sequelize, hasMany's use of through gives an error, and on the other hand through - option for belongsToMany has been made required. - * @see https://github.com/sequelize/sequelize/blob/v3.4.1/lib/associations/has-many.js - * @see https://github.com/sequelize/sequelize/blob/v3.4.1/lib/associations/belongs-to-many.js - */ - through: Class | string | ThroughOptions, - - /** - * The name of the foreign key in the join table (representing the target model) or an object representing - * the type definition for the other column (see `Sequelize.define` for syntax). When using an object, you - can add a `name` property to set the name of the colum. Defaults to the name of target + primary key of - target - */ - otherKey?: string | AssociationForeignKeyOptions, - - /** - * Should the join model have timestamps - */ - timestamps?: boolean - } - - - - /** - * Used for a association table in n:m associations. - * @see AssociationOptionsBelongsToMany - */ - declare export type ThroughOptions> = { - /** - * The model used to join both sides of the N:M association. - */ - model: Class, - - /** - * A key/value set that will be used for association create and find defaults on the through model. - * (Remember to add the attributes to the through model) - */ - scope?: ?AssociationScope, - - /** - * If true a unique key will be generated from the foreign keys used (might want to turn this off and create - * specific unique keys when using scopes) - - Defaults to true - */ - unique?: boolean - } - - declare type AssociationType = 'HasMany' | 'BelongsTo' | 'HasOne' | 'BelongsToMany' - - declare export type Attribute = { - /** - * A string or a data type - */ - type: DataTypeAbstract, - - allowNull?: boolean, - - values?: Array, - - /** - * If true, the column will get a unique constraint. If a string is provided, the column will be part of a - * composite unique index. If multiple columns have the same string, they will be part of the same unique - index - */ - unique?: boolean | string | { - name: string, - msg: string - }, - - /** - * Primary key flag - */ - primaryKey?: boolean, - - /** - * Is this field an auto increment field - */ - autoIncrement?: boolean, - - /** - * Comment for the database - */ - comment?: string, - - /** - * An object with reference configurations - */ - references?: string | Model | DefineAttributeColumnReferencesOptions, - - Model: Model, - _autoGenerated?: true, - fieldName: string, - field: string, - } - - declare export class Association, Target: Model> { - constructor(source: Class, target: Class, options?: AssociationOptions): this; - static BelongsTo: typeof BelongsTo; - static HasOne: typeof HasOne; - static BelongsToMany: typeof BelongsToMany; - static HasMany: typeof HasMany; - source: Class; - target: Class; - sequelize: Sequelize; - options: AssociationOptions; - scope: ?AssociationScope; - isSingleAssociation: boolean; - isMultiAssociation: boolean; - isSelfAssociation: boolean; - as: string | { - singular: string, - plural: string - }; - associationType: $Subtype; - } - - declare type ArrayOrElement = T | Array; - - declare class BelongsTo, TargetAttributes: Object, TargetInitAttributes: Object, Target: Model> extends Association { - associationType: 'BelongsTo'; - foreignKey: string; - foreignKeyField: string; - foreignKeyAttribute: Attribute; - identifier: string; - targetKey: string; - targetKeyField: string; - targetKeyAttribute: string; - targetIdentifier: string; - targetKeyIsPrimary: boolean; - identifierField: string; - get(instance: Source, options?: FindOptions): Promise; - get(instances: Array, options?: FindOptions): Promise<{[key: PrimaryKey]: Target}>; - set(sourceInstance: Source, targetInstance: PrimaryKey | Target, options?: InstanceSaveOptions): Promise; - create(sourceInstance: Source, values: TargetInitAttributes, options?: CreateOptions): Promise; - } - - declare class HasOne, TargetAttributes: Object, TargetInitAttributes: Object, Target: Model> extends Association { - associationType: 'HasOne'; - foreignKey: string; - foreignKeyField: string; - foreignKeyAttribute: Attribute; - identifier: string; - sourceKey: string; - sourceKeyField: string; - sourceKeyAttribute: string; - sourceKeyIsPrimary: boolean; - sourceIdentifier: string; - identifierField: string; - get(instance: Source, options?: FindOptions): Promise; - get(instances: Array, options?: FindOptions): Promise<{[key: PrimaryKey]: Target}>; - set(sourceInstance: Source, targetInstance: PrimaryKey | Target, options?: InstanceSaveOptions): Promise; - create(sourceInstance: Source, values: TargetInitAttributes, options?: CreateOptions): Promise; - } - - declare class HasMany, TargetAttributes: Object, TargetInitAttributes: Object, Target: Model> extends Association { - associationType: 'HasMany'; - foreignKey: string; - foreignKeyField: string; - foreignKeyAttribute: Attribute; - sourceKey: string; - sourceKeyField: string; - sourceKeyAttribute: string; - identifierField: string; - get(instance: Source, options?: FindOptions): Promise>; - get(instances: Array, options?: FindOptions): Promise<{[key: PrimaryKey]: Target}>; - count(instance: Source, options?: FindOptions): Promise; - has(sourceInstance: Source, targetInstances: ArrayOrElement, options?: FindOptions): Promise; - set(sourceInstance: Source, targetInstances: ArrayOrElement, options?: FindOptions & UpdateRelatedOptions): Promise; - add(sourceInstance: Source, targetInstances: ArrayOrElement, options?: UpdateRelatedOptions): Promise; - remove(sourceInstance: Source, targetInstances: ArrayOrElement, options?: UpdateRelatedOptions): Promise; - create(sourceInstance: Source, values: TargetInitAttributes, options?: CreateOptions): Promise; - } - - declare class BelongsToMany< - SourceAttributes: Object, - SourceInitAttributes: Object, - Source: Model, - TargetAttributes: Object, - TargetInitAttributes: Object, - Target: Model, - ThroughAttributes: Object, - Through: Model - > extends Association { - associationType: 'BelongsToMany'; - foreignKey: string; - foreignKeyField: string; - foreignKeyAttribute: Attribute; - otherKey: string; - otherKeyField: string; - otherKeyAttribute: string; - identifierField: string; - foreignIdentifierField?: string; - paired?: BelongsToMany; - through: ThroughOptions; - throughModel: Class; - get(instance: Source, options?: FindOptions): Promise>; - count(instance: Source, options?: FindOptions): Promise; - has(sourceInstance: Source, targetInstances: ArrayOrElement, options?: FindOptions): Promise; - set(sourceInstance: Source, targetInstances: ArrayOrElement, options?: FindOptions & UpdateRelatedOptions & DestroyOptions): Promise>; - add(sourceInstance: Source, targetInstances: ArrayOrElement, options?: FindOptions & UpdateRelatedOptions): Promise>; - remove(sourceInstance: Source, targetInstances: ArrayOrElement, options?: DestroyOptions): Promise; - create(sourceInstance: Source, values: TargetInitAttributes, options?: CreateOptions): Promise; - } - - /** - * Abstract DataType interface. Use this if you want to create an interface that has a value any of the - * DataTypes that Sequelize supports. - */ - declare export type DataTypeAbstract = { - /** - * Although this is not needed for the definitions itself, we want to make sure that DataTypeAbstract is not - * something than can be evaluated to an empty object. - */ - dialectTypes: string, - toSql(): string, - } - - declare type DataTypeAbstractString = { - /** - * A variable length string. Default length 255 - */ - (options?: { - length: number - }): T, - (length: number): T, - - /** - * Property BINARY for the type - */ - BINARY: T - } & DataTypeAbstract - - - declare type DataTypeString = {} & DataTypeAbstractString - - - declare type DataTypeChar = {} & DataTypeAbstractString - - - declare type DataTypeText = DataTypeAbstract & { - /** - * Length of the text field. - * - Available lengths: `tiny`, `medium`, `long` - */ - (options?: { - length: string - }): DataTypeText, - (length: string): DataTypeText - } - - - declare type DataTypeAbstractNumber = DataTypeAbstract & { - UNSIGNED: T, - ZEROFILL: T - } - - - declare type DataTypeNumber = DataTypeAbstractNumber & {} - - - declare type DataTypeInteger = DataTypeAbstractNumber & { - /** - * Length of the number field. - */ - (options?: { - length: number - }): DataTypeInteger, - (length: number): DataTypeInteger - } - - - declare type DataTypeBigInt = DataTypeAbstractNumber & { - /** - * Length of the number field. - */ - (options?: { - length: number - }): DataTypeBigInt, - (length: number): DataTypeBigInt - } - - - declare type DataTypeFloat = DataTypeAbstractNumber & { - /** - * Length of the number field and decimals of the float - */ - (options?: { - length: number, - decimals?: number - }): DataTypeFloat, - (length: number, decimals?: number): DataTypeFloat - } - - - declare type DataTypeReal = DataTypeAbstractNumber & { - /** - * Length of the number field and decimals of the real - */ - (options?: { - length: number, - decimals?: number - }): DataTypeReal, - (length: number, decimals?: number): DataTypeReal - } - - - declare type DataTypeDouble = DataTypeAbstractNumber & { - /** - * Length of the number field and decimals of the real - */ - (options?: { - length: number, - decimals?: number - }): DataTypeDouble, - (length: number, decimals?: number): DataTypeDouble - } - - - declare type DataTypeDecimal = DataTypeAbstractNumber & { - /** - * Precision and scale for the decimal number - */ - (options?: { - precision: number, - scale?: number - }): DataTypeDecimal, - (precision: number, scale?: number): DataTypeDecimal - } - - - declare type DataTypeBoolean = DataTypeAbstract & {} - - - declare type DataTypeTime = DataTypeAbstract & {} - - - declare type DataTypeDate = DataTypeAbstract & { - /** - * Length of decimal places of time - */ - (options?: { - length?: number - }): DataTypeDate, - (length?: number): DataTypeDate - } - - - declare type DataTypeDateOnly = DataTypeAbstract & {} - - - declare type DataTypeHStore = DataTypeAbstract & {} - - - declare type DataTypeJSONType = DataTypeAbstract & {} - - - declare type DataTypeJSONB = DataTypeAbstract & {} - - - declare type DataTypeNow = DataTypeAbstract & {} - - - declare type DataTypeBlob = DataTypeAbstract & { - /** - * Length of the blob field. - * - Available lengths: `tiny`, `medium`, `long` - */ - (options?: { - length: string - }): DataTypeBlob, - (length: string): DataTypeBlob - } - - - declare type DataTypeRange = DataTypeAbstract & { - /** - * Range field for Postgre - * - Accepts subtype any of the ranges - */ - (options?: { - subtype: DataTypeAbstract - }): DataTypeRange, - (subtype: DataTypeAbstract): DataTypeRange - } - - - declare type DataTypeUUID = DataTypeAbstract & {} - - - declare type DataTypeUUIDv1 = DataTypeAbstract & {} - - - declare type DataTypeUUIDv4 = DataTypeAbstract & {} - - declare class DataTypeVirtualClass { - constructor(subtype: DataTypeAbstract, requireAttributes?: Array): DataTypeVirtual; - } - - declare type DataTypeVirtual = DataTypeAbstract & typeof DataTypeVirtualClass & { - (subtype: DataTypeAbstract, requireAttributes?: Array): DataTypeVirtual; - } - - declare type DataTypeEnum = DataTypeAbstract & { - /** - * Enum field - * - Accepts values - */ - (options?: { - values: string | string[] - }): DataTypeEnum, - (values: string | string[]): DataTypeEnum, - (...args: string[]): DataTypeEnum - } - - - declare type DataTypeArray = DataTypeAbstract & { - /** - * Array field for Postgre - * - Accepts type any of the DataTypes - */ - (options: { - type: DataTypeAbstract - }): DataTypeArray, - (type: DataTypeAbstract): DataTypeArray - } - - - declare type DataTypeGeometry = DataTypeAbstract & { - /** - * Geometry field for Postgres - */ - (type: string, srid?: number): DataTypeGeometry - } - - - - /** - * A convenience class holding commonly used data types. The datatypes are used when definining a new model - * using - `Sequelize.define`, like this: - - ```js - sequelize.define('model', { - column: DataTypes.INTEGER - }) - ``` - When defining a model you can just as easily pass a string as type, but often using the types defined here - is - beneficial. For example, using `DataTypes.BLOB`, mean that that column will be returned as an instance of - `Buffer` when being fetched by sequelize. - - Some data types have special properties that can be accessed in order to change the data type. - For example, to get an unsigned integer with zerofill you can do `DataTypes.INTEGER.UNSIGNED.ZEROFILL`. - The order you access the properties in do not matter, so `DataTypes.INTEGER.ZEROFILL.UNSIGNED` is fine as - well. The available properties are listed under each data type. - - To provide a length for the data type, you can invoke it like a function: `INTEGER(2)` - - Three of the values provided here (`NOW`, `UUIDV1` and `UUIDV4`) are special default values, that should not - be used to define types. Instead they are used as shorthands for defining default values. For example, to - get a uuid field with a default value generated following v1 of the UUID standard: - - ```js - sequelize.define('model', { - uuid: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV1, - primaryKey: true - } - }) - ``` - */ - declare export type DataTypes = { - ABSTRACT: DataTypeAbstract, - STRING: DataTypeString, - CHAR: DataTypeChar, - TEXT: DataTypeText, - NUMBER: DataTypeNumber, - INTEGER: DataTypeInteger, - BIGINT: DataTypeBigInt, - FLOAT: DataTypeFloat, - TIME: DataTypeTime, - DATE: DataTypeDate, - DATEONLY: DataTypeDateOnly, - BOOLEAN: DataTypeBoolean, - NOW: DataTypeNow, - BLOB: DataTypeBlob, - DECIMAL: DataTypeDecimal, - NUMERIC: DataTypeDecimal, - UUID: DataTypeUUID, - UUIDV1: DataTypeUUIDv1, - UUIDV4: DataTypeUUIDv4, - HSTORE: DataTypeHStore, - JSON: DataTypeJSONType, - JSONB: DataTypeJSONB, - VIRTUAL: DataTypeVirtual, - ARRAY: DataTypeArray, - NONE: DataTypeVirtual, - ENUM: DataTypeEnum, - RANGE: DataTypeRange, - REAL: DataTypeReal, - DOUBLE: DataTypeDouble, - GEOMETRY: DataTypeGeometry, - } - - - /** - * Abstract Deferrable interface. Use this if you want to create an interface that has a value any of the - * Deferrables that Sequelize supports. - */ - declare export type DeferrableAbstract = { - /** - * Although this is not needed for the definitions itself, we want to make sure that DeferrableAbstract is - * not something than can be evaluated to an empty object. - */ - toString(): string, - toSql(): string - } - - declare export type DeferrableInitiallyDeferred = { - /** - * A property that will defer constraints checks to the end of transactions. - */ - (): DeferrableInitiallyDeferred - } & DeferrableAbstract - - - declare export type DeferrableInitiallyImmediate = { - /** - * A property that will trigger the constraint checks immediately - */ - (): DeferrableInitiallyImmediate - } & DeferrableAbstract - - - declare export type DeferrableNot = { - /** - * A property that will set the constraints to not deferred. This is the default in PostgreSQL and it make - * it impossible to dynamically defer the constraints within a transaction. - */ - (): DeferrableNot - } & DeferrableAbstract - - - declare export type DeferrableSetDeferred = { - /** - * A property that will trigger an additional query at the beginning of a - * transaction which sets the constraints to deferred. - * @param constraints An array of constraint names. Will defer all constraints by default. - */ - (constraints: string[]): DeferrableSetDeferred - } & DeferrableAbstract - - - declare export type DeferrableSetImmediate = { - /** - * A property that will trigger an additional query at the beginning of a - * transaction which sets the constraints to immediately. - * @param constraints An array of constraint names. Will defer all constraints by default. - */ - (constraints: string[]): DeferrableSetImmediate - } & DeferrableAbstract - - - - /** - * A collection of properties related to deferrable constraints. It can be used to - * make foreign key constraints deferrable and to set the constaints within a - transaction. This is only supported in PostgreSQL. - - The foreign keys can be configured like this. It will create a foreign key - that will check the constraints immediately when the data was inserted. - - ```js - sequelize.define('Model', { - foreign_id: { - type: Sequelize.INTEGER, - references: { - model: OtherModel, - key: 'id', - deferrable: Sequelize.Deferrable.INITIALLY_IMMEDIATE - } - } - }); - ``` - - The constraints can be configured in a transaction like this. It will - trigger a query once the transaction has been started and set the constraints - to be checked at the very end of the transaction. - - ```js - sequelize.transaction({ - deferrable: Sequelize.Deferrable.SET_DEFERRED - }); - ``` - */ - declare export type Deferrable = { - INITIALLY_DEFERRED: DeferrableInitiallyDeferred, - INITIALLY_IMMEDIATE: DeferrableInitiallyImmediate, - NOT: DeferrableNot, - SET_DEFERRED: DeferrableSetDeferred, - SET_IMMEDIATE: DeferrableSetImmediate - } - - - /** - * The Base Error all Sequelize Errors inherit from. - */ - declare export class BaseError extends Error { - - } - - declare export class ValidationError extends BaseError { - /** - * Validation Error. Thrown when the sequelize validation has failed. The error contains an `errors` - * property, which is an array with 1 or more ValidationErrorItems, one for each validation that failed. - * @param message Error message - * @param errors Array of ValidationErrorItem objects describing the validation errors - */ - constructor( - message: string, - errors?: ValidationErrorItem[]): ValidationError, - - /** - * Gets all validation error items for the path / field specified. - * @param path The path to be checked for error items - */ - get(path: string): ValidationErrorItem[], - - /** - * Array of ValidationErrorItem objects describing the validation errors - */ - errors: ValidationErrorItem[] - } - - - declare export class ValidationErrorItem extends BaseError { - /** - * Validation Error Item - * Instances of this class are included in the `ValidationError.errors` property. - * @param message An error message - * @param type The type of the validation error - * @param path The field that triggered the validation error - * @param value The value that generated the error - */ - constructor( - message: string, - type: string, - path: string, - value: string): ValidationErrorItem, - - /** - * An error message - */ - message: string, - - /** - * The type of the validation error - */ - type: string, - - /** - * The field that triggered the validation error - */ - path: string, - - /** - * The value that generated the error - */ - value: string - } - - - declare export class DatabaseError extends BaseError { - /** - * A base class for all database related errors. - */ - constructor(parent: Error): DatabaseError - } - - - declare export class TimeoutError extends DatabaseError { - /** - * Thrown when a database query times out because of a deadlock - */ - constructor(parent: Error): TimeoutError - } - - - declare export class UniqueConstraintError extends ValidationError { - /** - * Thrown when a unique constraint is violated in the database - */ - constructor( - options: { - parent?: Error, - message?: string, - errors?: Object - }): UniqueConstraintError - } - - - declare export class ForeignKeyConstraintError extends DatabaseError { - /** - * Thrown when a foreign key constraint is violated in the database - */ - construtor( - options: { - parent?: Error, - message?: string, - index?: string, - fields?: string[], - table?: string - }): ForeignKeyConstraintError - } - - - declare export class ExclusionConstraintError extends DatabaseError { - /** - * Thrown when an exclusion constraint is violated in the database - */ - construtor( - options: { - parent?: Error, - message?: string, - constraint?: string, - fields?: string[], - table?: string - }): ExclusionConstraintError - } - - - declare export class ConnectionError extends BaseError { - /** - * A base class for all connection related errors. - */ - construtor(parent: Error): ConnectionError - } - - - declare export class ConnectionRefusedError extends ConnectionError { - /** - * Thrown when a connection to a database is refused - */ - construtor(parent: Error): ConnectionRefusedError - } - - - declare export class AccessDeniedError extends ConnectionError{ - /** - * Thrown when a connection to a database is refused due to insufficient privileges - */ - construtor(parent: Error): AccessDeniedError - } - - - declare export class HostNotFoundError extends ConnectionError { - /** - * Thrown when a connection to a database has a hostname that was not found - */ - construtor(parent: Error): HostNotFoundError - } - - - declare export class HostNotReachableError extends ConnectionError { - /** - * Thrown when a connection to a database has a hostname that was not reachable - */ - construtor(parent: Error): HostNotReachableError - } - - - declare export class InvalidConnectionError extends ConnectionError { - /** - * Thrown when a connection to a database has invalid values for any of the connection parameters - */ - construtor(parent: Error): InvalidConnectionError - } - - - declare export class ConnectionTimedOutError extends ConnectionError { - /** - * Thrown when a connection to a database times out - */ - construtor(parent: Error): ConnectionTimedOutError - } - - - declare export class EmptyResultError extends BaseError { - /** - * Thrown when a record was not found, Usually used with rejectOnEmpty mode (see message for details) - */ - construtor(parent: Error): EmptyResultError - } - - /** - * Options for Sequelize.define. We mostly duplicate the Hooks here, since there is no way to combine the two - * interfaces. - - beforeValidate, afterValidate, beforeBulkCreate, beforeBulkDestroy, beforeBulkUpdate, beforeCreate, - beforeDestroy, beforeUpdate, afterCreate, afterDestroy, afterUpdate, afterBulkCreate, afterBulkDestroy and - afterBulkUpdate. - */ - declare export type HooksDefineOptions> = { - beforeValidate?: AsyncFn2, - validationFailed?: AsyncFn3, - afterValidate?: AsyncFn2, - beforeCreate?: AsyncFn2, - afterCreate?: AsyncFn2, - beforeDestroy?: AsyncFn2, - beforeDelete?: AsyncFn2, - afterDestroy?: AsyncFn2, - afterDelete?: AsyncFn2, - beforeUpdate?: AsyncFn2, - afterUpdate?: AsyncFn2, - beforeBulkCreate?: AsyncFn2, - afterBulkCreate?: AsyncFn2, - beforeBulkDestroy?: AsyncFn1, - beforeBulkDelete?: AsyncFn1, - afterBulkDestroy?: AsyncFn1, - afterBulkDelete?: AsyncFn1, - beforeBulkUpdate?: AsyncFn1, - afterBulkUpdate?: AsyncFn1, - beforeFind?: AsyncFn1, - beforeFindAfterExpandIncludeAll?: AsyncFn1, - beforeFindAfterOptions?: AsyncFn1, - afterFind?: AsyncFn2, - } - - - /** - * Options used for Instance.increment method - */ - declare export type InstanceIncrementDecrementOptions = { - /** - * The number to increment by - * Defaults to 1 - */ - by?: number, - - /** - * If true, the updatedAt timestamp will not be updated. - */ - silent?: boolean, - - /** - * A function that gets executed while running the query to log the sql. - */ - logging?: boolean | Function, - - /** - * Transaction to run query under - */ - transaction?: ?Transaction, - - /** - * An optional parameter to specify the schema search_path (Postgres only) - */ - searchPath?: string, - } - - - /** - * Options used for Instance.restore method - */ - declare export type InstanceRestoreOptions = { - /** - * A function that gets executed while running the query to log the sql. - */ - logging?: boolean | Function, - - /** - * Transaction to run query under - */ - transaction?: ?Transaction - } - - - /** - * Options used for Instance.destroy method - */ - declare export type InstanceDestroyOptions = { - /** - * If set to true, paranoid models will actually be deleted - */ - force?: boolean, - - /** - * A function that gets executed while running the query to log the sql. - */ - logging?: boolean | Function, - - /** - * Transaction to run the query in - */ - transaction?: ?Transaction - } - - - /** - * Options used for Instance.update method - */ - declare export type InstanceUpdateOptions = { - /** - * A hash of attributes to describe your search. See above for examples. - */ - where?: WhereOptions, - } & InstanceSaveOptions & InstanceSetOptions - - - - /** - * Options used for Instance.set method - */ - declare export type InstanceSetOptions = { - /** - * If set to true, field and virtual setters will be ignored - */ - raw?: boolean, - - /** - * Clear all previously set data values - */ - reset?: boolean - } - - - /** - * Options used for Instance.save method - */ - declare export type InstanceSaveOptions = { - /** - * If true, the updatedAt timestamp will not be updated. - * - Defaults to false - */ - silent?: boolean - } & FieldsOptions & LoggingOptions & ReturningOptions & SearchPathOptions - - declare export type LoggingOptions = { - /** - * A function that gets executed while running the query to log the sql. - */ - logging?: boolean | Function, - - /** - * Print query execution time in milliseconds when logging SQL. - */ - benchmark?: boolean - } - - declare export type SearchPathOptions = { - /** - * Transaction to run query under - */ - transaction?: ?Transaction, - - /** - * An optional parameter to specify the schema search_path (Postgres only) - */ - searchPath?: string - } - - declare export type ReturningOptions = { - /** - * Append RETURNING to get back auto generated values (Postgres only) - */ - returning?: boolean - } - - declare export type FieldsOptions = { - /** - * Run validations before the row is inserted - */ - validate?: boolean, - - /** - * The fields to insert / update. Defaults to all fields - */ - fields?: $Keys[] - } - - - /** - * Options to pass to Model on drop - */ - declare export type DropOptions = { - /** - * Also drop all objects depending on this table, such as views. Only works in postgres - */ - cascade?: boolean - } & LoggingOptions - - - - /** - * Schema Options provided for applying a schema to a model - */ - declare export type SchemaOptions = { - /** - * The character(s) that separates the schema name from the table name - */ - schemaDelimeter?: string - } & LoggingOptions - - - - /** - * GetTableName Options - */ - declare export type GetTableNameOptions = {} & LoggingOptions - - - - /** - * AddScope Options for Model.addScope - */ - declare export type AddScopeOptions = { - /** - * If a scope of the same name already exists, should it be overwritten? - */ - override: boolean - } - - - /** - * Scope Options for Model.scope - */ - declare export type ScopeOptions = { - /** - * The scope(s) to apply. Scopes can either be passed as consecutive arguments, or as an array of arguments. - * To apply simple scopes and scope functions with no arguments, pass them as strings. For scope function, - pass an object, with a `method` property. The value can either be a string, if the method does not take - any arguments, or an array, where the first element is the name of the method, and consecutive elements - are arguments to that method. Pass null to remove all scopes, including the default. - */ - method: string | any[], - } - - /** - * The type accepted by every `where` option - * - * The `Array` is to support string with replacements, like `['id > ?', 25]` - */ - declare export type WhereOptions = WhereAttributeHash | AndOperator | OrOperator | where | fn | $ReadOnlyArray; - - /** - * Example: `$any: [2,3]` becomes `ANY ARRAY[2, 3]::INTEGER` - * - * _PG only_ - */ - declare export type AnyOperator = { - $any: $ReadOnlyArray; - } - - /** Undocumented? */ - declare export type AllOperator = { - $all: $ReadOnlyArray; - } - - /** - * Operators that can be used in WhereOptions - * - * See http://docs.sequelizejs.com/en/v3/docs/querying/#operators - */ - declare export type WhereOperators = { - - /** - * Example: `$any: [2,3]` becomes `ANY ARRAY[2, 3]::INTEGER` - * - * _PG only_ - */ - $any?: $ReadOnlyArray; - - /** Example: `$gte: 6,` becomes `>= 6` */ - $gte?: number | string | Date; - - /** Example: `$lt: 10,` becomes `< 10` */ - $lt?: number | string | Date; - - /** Example: `$lte: 10,` becomes `<= 10` */ - $lte?: number | string | Date; - - /** Example: `$ne: 20,` becomes `!= 20` */ - $ne?: string | number | WhereOperators; - - /** Example: `$not: true,` becomes `IS NOT TRUE` */ - $not?: boolean | string | number | WhereOperators; - - /** Example: `$between: [6, 10],` becomes `BETWEEN 6 AND 10` */ - $between?: [number, number]; - - /** Example: `$in: [1, 2],` becomes `IN [1, 2]` */ - $in?: $ReadOnlyArray | literal; - - /** Example: `$notIn: [1, 2],` becomes `NOT IN [1, 2]` */ - $notIn?: $ReadOnlyArray | literal; - - /** - * Examples: - * - `$like: '%hat',` becomes `LIKE '%hat'` - * - `$like: { $any: ['cat', 'hat']}` becomes `LIKE ANY ARRAY['cat', 'hat']` - */ - $like?: string | AnyOperator | AllOperator; - - /** - * Examples: - * - `$notLike: '%hat'` becomes `NOT LIKE '%hat'` - * - `$notLike: { $any: ['cat', 'hat']}` becomes `NOT LIKE ANY ARRAY['cat', 'hat']` - */ - $notLike?: string | AnyOperator | AllOperator; - - /** - * case insensitive PG only - * - * Examples: - * - `$iLike: '%hat'` becomes `ILIKE '%hat'` - * - `$iLike: { $any: ['cat', 'hat']}` becomes `ILIKE ANY ARRAY['cat', 'hat']` - */ - $ilike?: string | AnyOperator | AllOperator; - - /** - * case insensitive PG only - * - * Examples: - * - `$iLike: '%hat'` becomes `ILIKE '%hat'` - * - `$iLike: { $any: ['cat', 'hat']}` becomes `ILIKE ANY ARRAY['cat', 'hat']` - */ - $iLike?: string | AnyOperator | AllOperator; - - /** - * PG array overlap operator - * - * Example: `$overlap: [1, 2]` becomes `&& [1, 2]` - */ - $overlap?: [number, number]; - - /** - * PG array contains operator - * - * Example: `$contains: [1, 2]` becomes `@> [1, 2]` - */ - $contains?: any[]; - - /** - * PG array contained by operator - * - * Example: `$contained: [1, 2]` becomes `<@ [1, 2]` - */ - $contained?: any[]; - - /** Example: `$gt: 6,` becomes `> 6` */ - $gt?: number | string | Date; - - /** - * PG only - * - * Examples: - * - `$notILike: '%hat'` becomes `NOT ILIKE '%hat'` - * - `$notLike: ['cat', 'hat']` becomes `LIKE ANY ARRAY['cat', 'hat']` - */ - $notILike?: string | AnyOperator | AllOperator; - - /** Example: `$notBetween: [11, 15],` becomes `NOT BETWEEN 11 AND 15` */ - $notBetween?: [number, number]; - } | {[op: Symbol]: any} - - /** Example: `$or: [{a: 5}, {a: 6}]` becomes `(a = 5 OR a = 6)` */ - declare export type OrOperator = { - [$or: Symbol | '$or']: WhereOperators | WhereAttributeHash | $ReadOnlyArray | Array | WhereOperators | WhereAttributeHash | where | AndOperator>; - } - - /** Example: `$and: {a: 5}` becomes `AND (a = 5)` */ - declare export type AndOperator = { - [$and: Symbol | '$and']: WhereOperators | WhereAttributeHash | $ReadOnlyArray | Array | WhereOperators | WhereAttributeHash | where | OrOperator>; - } - - /** - * Where Geometry Options - */ - declare export type WhereGeometryOptions = { - type: string; - coordinates: $ReadOnlyArray | number>; - } - - /** - * Used for the right hand side of WhereAttributeHash. - * WhereAttributeHash is in there for JSON columns. - */ - declare export type WhereValue = - string // literal value - | number // literal value - | boolean // literal value - | null - | WhereOperators - | WhereAttributeHash // for JSON columns - | col // reference another column - | OrOperator - | AndOperator - | WhereGeometryOptions - | $ReadOnlyArray; // implicit $or - - /** - * A hash of attributes to describe your search. - */ - declare export type WhereAttributeHash = { - /** - * Possible key values: - * - A simple attribute name - * - A nested key for JSON columns - * - * { - * "meta.audio.length": { - * $gt: 20 - * } - * } - */ - [field: string]: WhereValue; - } - - /** - * Through options for Include Options - */ - declare export type IncludeThroughOptions = { - /** - * Filter on the join model for belongsToMany relations - */ - where?: WhereOptions, - - /** - * A list of attributes to select from the join model for belongsToMany relations - */ - attributes?: string[] - } - - /** - * Complex include options - */ - declare export type IncludeOptions> = { - /** - * The model you want to eagerly load - */ - model?: Class, - - /** - * The alias of the relation, in case the model you want to eagerly load is aliassed. For `hasOne` / - * `belongsTo`, this should be the singular name, and for `hasMany`, it should be the plural - */ - as?: string, - - /** - * The association you want to eagerly load. (This can be used instead of providing a model/as pair) - */ - association?: Association, - - /** - * Where clauses to apply to the child models. Note that this converts the eager load to an inner join, - * unless you explicitly set `required: false` - */ - where?: WhereOptions, - - /** - * A list of attributes to select from the child model - */ - attributes?: FindOptionsAttributesArray | { - include?: FindOptionsAttributesArray, - exclude?: Array<$Keys> - }, - - /** - * If true, converts to an inner join, which means that the parent model will only be loaded if it has any - * matching children. True if `include.where` is set, false otherwise. - */ - required?: boolean, - - /** - * Through Options - */ - through?: IncludeThroughOptions, - - /** - * Load further nested related models - */ - include?: $ReadOnlyArray> | IncludeOptions>, - - /** - * If true, only non-deleted records will be returned. If false, both deleted and non-deleted records will - * be returned. Only applies if `options.paranoid` is true for the model. - */ - paranoid?: boolean, - all?: boolean | string - } - - - /** - * Shortcut for types used in FindOptions.attributes - */ - declare export type FindOptionsAttributesArray = Array< - $Keys | - literal | - [fn, string] | - [cast, string] | - [literal, string] | - [$Keys, string] | - fn | - cast - >; - - - /** - * Options that are passed to any model creating a SELECT query - * - A hash of options to describe the scope of the search - */ - declare export type FindOptions= { - /** - * A hash of attributes to describe your search. See above for examples. - */ - where?: WhereOptions, - - /** - * A list of the attributes that you want to select. To rename an attribute, you can pass an array, with - * two elements - the first is the name of the attribute in the DB (or some kind of expression such as - `Sequelize.literal`, `Sequelize.fn` and so on), and the second is the name you want the attribute to - have in the returned instance - */ - attributes?: FindOptionsAttributesArray | { - include?: FindOptionsAttributesArray, - exclude?: Array<$Keys> - }, - - /** - * If true, only non-deleted records will be returned. If false, both deleted and non-deleted records will - * be returned. Only applies if `options.paranoid` is true for the model. - */ - paranoid?: boolean, - - /** - * A list of associations to eagerly load using a left join. Supported is either - * `{ include: [ Model1, Model2, ...]}` or `{ include: [{ model: Model1, as: 'Alias' }]}`. - If your association are set up with an `as` (eg. `X.hasMany(Y, { as: 'Z }`, you need to specify Z in - the as attribute when eager loading Y). - */ - include?: $ReadOnlyArray> | IncludeOptions>, - - /** - * Specifies an ordering. If a string is provided, it will be escaped. Using an array, you can provide - * several columns / functions to order by. Each element can be further wrapped in a two-element array. The - first element is the column / function to order by, the second is the direction. For example: - `order: [['name', 'DESC']]`. In this way the column will be escaped, but the direction will not. - */ - order?: - string | - col | - literal | - $ReadOnlyArray< - string | - col | - literal | - Class> | - {model: Class>, as?: string} | - $ReadOnlyArray< - string | - number | - Class> | - {model: Class>, as?: string} - > - >, - - /** - * Limit the results - */ - limit?: number, - - /** - * Skip the results; - */ - offset?: number, - - /** - * Lock the selected rows. Possible options are transaction.LOCK.UPDATE and transaction.LOCK.SHARE. - * Postgres also supports transaction.LOCK.KEY_SHARE, transaction.LOCK.NO_KEY_UPDATE and specific model - locks with joins. See [transaction.LOCK for an example](transaction#lock) - */ - lock?: TransactionLockLevel | { - level: TransactionLockLevel, - of: Class> - }, - - /** - * Return raw result. See sequelize.query for more information. - */ - raw?: boolean, - - /** - * having ?!? - */ - having?: WhereOptions, - - /** - * Group by. It is not mentioned in sequelize's JSDoc, but mentioned in docs. - * https://github.com/sequelize/sequelize/blob/master/docs/docs/models-usage.md#user-content-manipulating-the-dataset-with-limit-offset-order-and-group - */ - group?: string | string[] | Object, - - /** - * Apply DISTINCT(col) for FindAndCount(all) - */ - distinct?: boolean, - - /** - * Prevents a subquery on the main table when using include - */ - subQuery?: boolean, - - /** - * Throw EmptyResultError if a record is not found - */ - rejectOnEmpty?: boolean - } & LoggingOptions & SearchPathOptions - - - declare export type AnyFindOptions = FindOptions; - - - /** - * Options for Model.count method - */ - declare export type CountOptions = { - /** - * A hash of search attributes. - */ - where?: WhereOptions, - - /** - * Include options. See `find` for details - */ - include?: $ReadOnlyArray>| IncludeOptions>, - - /** - * Apply COUNT(DISTINCT(col)) - */ - distinct?: boolean, - - /** - * Used in conjustion with `group` - */ - attributes?: $ReadOnlyArray, - - /** - * For creating complex counts. Will return multiple rows as needed. - * - TODO: Check? - */ - group?: Object | Array, - } & LoggingOptions & SearchPathOptions - - - - /** - * Options for Model.build method - */ - declare export type BuildOptions = { - /** - * If set to true, values will ignore field and virtual setters. - */ - raw?: boolean, - - /** - * Is this record new - */ - isNewRecord?: boolean, - - /** - * an array of include options - Used to build prefetched/included model instances. See `set` - * - TODO: See set - */ - include?: $ReadOnlyArray> | IncludeOptions> - } & ReturningOptions - - - - /** - * Options for Model.create method - */ - declare export type CreateOptions = { - /** - * On Duplicate - */ - onDuplicate?: string - } & BuildOptions & InstanceSaveOptions - - - - /** - * Options for Model.findOrInitialize method - */ - declare export type FindOrInitializeOptions= { - /** - * Default values to use if building a new instance - */ - defaults?: $Shape - } & FindOptions - - - - /** - * Options for Model.findOrInitialize method - */ - declare export type FindCreateFindOptions= { - /** - * Default values to use if building a new instance - */ - defaults?: $Shape - } & FindOptions - - - - /** - * Options for Model.upsert method - * - */ - declare export type UpsertOptions = {} & FieldsOptions & LoggingOptions & SearchPathOptions - - - - /** - * Options for Model.bulkCreate method - */ - declare export type BulkCreateOptions = { - /** - * Run before / after bulk create hooks? - */ - hooks?: boolean, - - /** - * Run before / after create hooks for each individual Instance? BulkCreate hooks will still be run if - * options.hooks is true. - */ - individualHooks?: boolean, - - /** - * Ignore duplicate values for primary keys? (not supported by postgres) - * - Defaults to false - */ - ignoreDuplicates?: boolean, - - /** - * Fields to update if row key already exists (on duplicate key update)? (only supported by mysql & - * mariadb). By default, all fields are updated. - */ - updateOnDuplicate?: string[] - } & FieldsOptions & LoggingOptions & SearchPathOptions & ReturningOptions - - - - /** - * The options passed to Model.destroy in addition to truncate - */ - declare export type TruncateOptions = { - /** - * Only used in conjuction with TRUNCATE. Truncates all tables that have foreign-key references to the - * named table, or to any tables added to the group due to CASCADE. - - Defaults to false; - */ - cascade?: boolean, - - /** - * Delete instead of setting deletedAt to current timestamp (only applicable if paranoid is enabled) - * - Defaults to false; - */ - force?: boolean - } & LoggingOptions & SearchPathOptions - - - - /** - * Options used for Model.destroy - */ - declare export type DestroyOptions = { - /** - * Filter the destroy - */ - where?: WhereOptions, - - /** - * Run before / after bulk destroy hooks? - */ - hooks?: boolean, - - /** - * If set to true, destroy will SELECT all records matching the where parameter and will execute before / - * after destroy hooks on each row - */ - individualHooks?: boolean, - - /** - * How many rows to delete - */ - limit?: number, - - /** - * Delete instead of setting deletedAt to current timestamp (only applicable if `paranoid` is enabled) - */ - force?: boolean, - - /** - * If set to true, dialects that support it will use TRUNCATE instead of DELETE FROM. If a table is - * truncated the where and limit options are ignored - */ - truncate?: boolean - } & TruncateOptions - - declare type AsyncFn1 = (a: A, callback: (error?: Error) => any) => ?Promise - declare type AsyncFn2 = ((a: A, b: B, callback: (error?: Error) => any) => ?Promise) - declare type AsyncFn3 = ((a: A, b: B, c: C, callback: (error?: Error) => any) => ?Promise) - - /** - * Options for Model.restore - */ - declare export type RestoreOptions = { - /** - * Filter the restore - */ - where?: WhereOptions, - - /** - * Run before / after bulk restore hooks? - */ - hooks?: boolean, - - /** - * If set to true, restore will find all records within the where parameter and will execute before / after - * bulkRestore hooks on each row - */ - individualHooks?: boolean, - - /** - * How many rows to undelete - */ - limit?: number, - - /** - * Transaction to run query under - */ - transaction?: ?Transaction - } & LoggingOptions - - /** - * Options used for HasMany.update, BelongsToMany.update - */ - declare export type UpdateRelatedOptions = { - /** - * Options to describe the scope of the search. - */ - where?: WhereOptions, - - /** - * Run before / after bulk update hooks? - * - Defaults to true - */ - hooks?: boolean, - - /** - * Whether or not to update the side effects of any virtual setters. - * - Defaults to true - */ - sideEffects?: boolean, - - /** - * Run before / after update hooks?. If true, this will execute a SELECT followed by individual UPDATEs. - * A select is needed, because the row data needs to be passed to the hooks - - Defaults to false - */ - individualHooks?: boolean, - - /** - * How many rows to update (only for mysql and mariadb) - */ - limit?: number, - - /** - * Transaction to run query under - */ - transaction?: ?Transaction, - - /** - * If true, the updatedAt timestamp will not be updated. - */ - silent?: boolean - } & FieldsOptions & LoggingOptions & ReturningOptions - - - /** - * Options used for Model.update - */ - declare export type UpdateOptions = { - /** - * Options to describe the scope of the search. - */ - where: WhereOptions, - - /** - * Run before / after bulk update hooks? - * - Defaults to true - */ - hooks?: boolean, - - /** - * Whether or not to update the side effects of any virtual setters. - * - Defaults to true - */ - sideEffects?: boolean, - - /** - * Run before / after update hooks?. If true, this will execute a SELECT followed by individual UPDATEs. - * A select is needed, because the row data needs to be passed to the hooks - - Defaults to false - */ - individualHooks?: boolean, - - /** - * How many rows to update (only for mysql and mariadb) - */ - limit?: number, - - /** - * Transaction to run query under - */ - transaction?: ?Transaction, - - /** - * If true, the updatedAt timestamp will not be updated. - */ - silent?: boolean - } & FieldsOptions & LoggingOptions & ReturningOptions - - - - /** - * Options used for Model.aggregate - */ - declare export type AggregateOptions = { - /** - * A hash of search attributes. - */ - where?: WhereOptions, - - /** - * The type of the result. If `field` is a field in this Model, the default will be the type of that field, - * otherwise defaults to float. - */ - dataType?: DataTypeAbstract | string, - - /** - * Applies DISTINCT to the field being aggregated over - */ - distinct?: boolean, - - /** - * The transaction that the query should be executed under - */ - transaction?: ?Transaction, - - /** - * When `true`, the first returned value of `aggregateFunction` is cast to `dataType` and returned. - * If additional attributes are specified, along with `group` clauses, set `plain` to `false` to return all values of all returned rows. - Defaults to `true` - */ - plain?: boolean - } & LoggingOptions - - - - /** - * A Model represents a table in the database. Sometimes you might also see it referred to as model, or simply - * as factory. This class should _not_ be instantiated directly, it is created using `sequelize.define`, and - already created models can be loaded using `sequelize.import` - */ - declare export class Model { - static init(attributes: DefineAttributes, options: DefineOptions): this, - - static QueryInterface: QueryInterface, - - static QueryGenerator: any, - - static sequelize: Sequelize, - - sequelize: Sequelize, - - /** - * The options this model was initialized with - */ - static options: ResolvedDefineOptions, - - /** - * Remove attribute from model definition - * @param attribute - */ - static removeAttribute(attribute: string): void, - - /** - * Sync this Model to the DB, that is create the table. Upon success, the callback will be called with the - * model instance (this) - */ - static sync(options?: SyncOptions): Promise, - - /** - * Drop the table represented by this Model - * @param options - */ - static drop(options?: DropOptions): Promise, - - /** - * Apply a schema to this model. For postgres, this will actually place the schema in front of the table - * name - - `"schema"."tableName"`, while the schema will be prepended to the table name for mysql and - sqlite - `'schema.tablename'`. - * @param schema The name of the schema - * @param options - */ - static schema(schema: string, options?: SchemaOptions): Class, - - /** - * Get the tablename of the model, taking schema into account. The method will return The name as a string - * if the model has no schema, or an object with `tableName`, `schema` and `delimiter` properties. - * @param options The hash of options from any query. You can use one model to access tables with matching - schemas by overriding `getTableName` and using custom key/values to alter the name of the table. - (eg. - subscribers_1, subscribers_2) - * @param options .logging=false A function that gets executed while running the query to log the sql. - */ - static getTableName(options?: GetTableNameOptions): string | Object, - - /** - * Add a new scope to the model. This is especially useful for adding scopes with includes, when the model you want to include is not available at the time this model is defined. - * - By default this will throw an error if a scope with that name already exists. Pass `override: true` in the options object to silence this error. - * @param The name of the scope. Use `defaultScope` to override the default scope - * @param - * @param * - * @param .override=false] - */ - static addScope( - name: string, - scope: AnyFindOptions | Function, - options?: AddScopeOptions): void, - - /** - * Apply a scope created in `define` to the model. First let's look at how to create scopes: - * ```js - var Model = sequelize.define('model', attributes, { - defaultScope: { - where: { - username: 'dan' - }, - limit: 12 - }, - scopes: { - isALie: { - where: { - stuff: 'cake' - } - }, - complexFunction: function(email, accessLevel) { - return { - where: { - email: { - $like: email - }, - accesss_level { - $gte: accessLevel - } - } - } - } - } - }) - ``` - Now, since you defined a default scope, every time you do Model.find, the default scope is appended to - your query. Here's a couple of examples: - ```js - Model.findAll() // WHERE username = 'dan' - Model.findAll({ where: { age: { gt: 12 } } }) // WHERE age>12 AND username = 'dan' - ``` - - To invoke scope functions you can do: - ```js - Model.scope({ method: ['complexFunction' 'dan@sequelize.com', 42]}).findAll() - // WHERE email like 'dan@sequelize.com%' AND access_level>= 42 - ``` - * @return Model A reference to the model, with the scope(s) applied. Calling scope again on the returned - model will clear the previous scope. - */ - static scope( - options?: string | ScopeOptions | $ReadOnlyArray): Class, - - /** - * Search for multiple instances. - * - __Simple search using AND and =__ - ```js - Model.findAll({ - where: { - attr1: 42, - attr2: 'cake' - } - }) - ``` - ```sql - WHERE attr1 = 42 AND attr2 = 'cake' - ``` - - __Using greater than, less than etc.__ - ```js - - Model.findAll({ - where: { - attr1: { - gt: 50 - }, - attr2: { - lte: 45 - }, - attr3: { - in: [1,2,3] - }, - attr4: { - ne: 5 - } - } - }) - ``` - ```sql - WHERE attr1>50 AND attr2 <= 45 AND attr3 IN (1,2,3) AND attr4 != 5 - ``` - Possible options are: `$ne, $in, $not, $notIn, $gte, $gt, $lte, $lt, $like, $ilike/$iLike, $notLike, - $notILike, '..'/$between, '!..'/$notBetween, '&&'/$overlap, '@>'/$contains, '<@'/$contained` - - __Queries using OR__ - ```js - Model.findAll({ - where: Sequelize.and( - { name: 'a project' }, - Sequelize.or( - { id: [1,2,3] }, - { id: { gt: 10 } } - ) - ) - }) - ``` - ```sql - WHERE name = 'a project' AND (id` IN (1,2,3) OR id>10) - ``` - - The success listener is called with an array of instances if the query succeeds. - * @see {Sequelize#query} - */ - static findAll( - options?: FindOptions): Promise, - static all( - optionz?: FindOptions): Promise, - - /** - * Search for a single instance by its primary key. This applies LIMIT 1, so the listener will - * always be called with a single instance. - */ - static findById( - identifier?: number | string, - options?: FindOptions): Promise, - static findByPrimary( - identifier?: number | string, - options?: FindOptions): Promise, - - /** - * Search for a single instance. This applies LIMIT 1, so the listener will always be called with a single - * instance. - */ - static findOne( - options?: FindOptions): Promise, - static find( - options?: FindOptions): Promise, - - /** - * Run an aggregation method on the specified field - * @param field The field to aggregate over. Can be a field name or * - * @param aggregateFunction The function to use for aggregation, e.g. sum, max etc. - * @param options Query options. See sequelize.query for full options - * @return Returns the aggregate result cast to `options.dataType`, unless `options.plain` is false, in - which case the complete data result is returned. - */ - static aggregate( - field: string, - aggregateFunction: string, - options?: AggregateOptions): Promise, - - /** - * Count the number of records matching the provided where clause. - * - If you provide an `include` option, the number of matching associations will be counted instead. - */ - static count(options?: CountOptions): Promise, - - /** - * Find all the rows matching your query, within a specified offset / limit, and get the total number of - * rows matching your query. This is very usefull for paging - - ```js - Model.findAndCountAll({ - where: ..., - limit: 12, - offset: 12 - }).then(function (result) { - ... - }) - ``` - In the above example, `result.rows` will contain rows 13 through 24, while `result.count` will return - the - total number of rows that matched your query. - - When you add includes, only those which are required (either because they have a where clause, or - because - `required` is explicitly set to true on the include) will be added to the count part. - - Suppose you want to find all users who have a profile attached: - ```js - User.findAndCountAll({ - include: [ - { model: Profile, required: true} - ], - limit 3 - }); - ``` - Because the include for `Profile` has `required` set it will result in an inner join, and only the users - who have a profile will be counted. If we remove `required` from the include, both users with and - without - profiles will be counted - */ - static findAndCount( - options?: FindOptions): Promise<{ - rows: this[], - count: number - }>, - static findAndCountAll( - options?: FindOptions): Promise<{ - rows: this[], - count: number - }>, - - /** - * Find the maximum value of field - */ - static max(field: string, options?: AggregateOptions): Promise, - - /** - * Find the minimum value of field - */ - static min(field: string, options?: AggregateOptions): Promise, - - /** - * Find the sum of field - */ - static sum(field: string, options?: AggregateOptions): Promise, - - /** - * Builds a new model instance. Values is an object of key value pairs, must be defined but can be empty. - */ - static build(record?: TInitAttributes, options?: BuildOptions): this, - - /** - * Undocumented bulkBuild - */ - static bulkBuild(records: TInitAttributes[], options?: BuildOptions): this[], - - /** - * Builds a new model instance and calls save on it. - */ - static create(values?: TInitAttributes, options?: CreateOptions): Promise, - - /** - * Find a row that matches the query, or build (but don't save) the row if none is found. - * The successfull result of the promise will be (instance, initialized) - Make sure to use .spread() - */ - static findOrInitialize( - options: FindOrInitializeOptions): Promise<[this, boolean]>, - static findOrBuild( - options: FindOrInitializeOptions): Promise<[this, boolean]>, - - /** - * Find a row that matches the query, or build and save the row if none is found - * The successful result of the promise will be (instance, created) - Make sure to use .spread() - - If no transaction is passed in the `options` object, a new transaction will be created internally, to - prevent the race condition where a matching row is created by another connection after the find but - before the insert call. However, it is not always possible to handle this case in SQLite, specifically - if one transaction inserts and another tries to select before the first one has comitted. In this case, - an instance of sequelize.TimeoutError will be thrown instead. If a transaction is created, a savepoint - will be created instead, and any unique constraint violation will be handled internally. - */ - static findOrCreate( - options: FindOrInitializeOptions): Promise<[this, boolean]>, - - /** - * A more performant findOrCreate that will not work under a transaction (at least not in postgres) - * Will execute a find call, if empty then attempt to create, if unique constraint then attempt to find again - */ - static findCreateFind( - options: FindCreateFindOptions): Promise<[this, boolean]>, - - /** - * Insert or update a single row. An update will be executed if a row which matches the supplied values on - * either the primary key or a unique key is found. Note that the unique index must be defined in your - sequelize model and not just in the table. Otherwise you may experience a unique constraint violation, - because sequelize fails to identify the row that should be updated. - - *Implementation details:* - - * MySQL - Implemented as a single query `INSERT values ON DUPLICATE KEY UPDATE values` - * PostgreSQL - Implemented as a temporary function with exception handling: INSERT EXCEPTION WHEN - unique_constraint UPDATE - * SQLite - Implemented as two queries `INSERT; UPDATE`. This means that the update is executed - regardless - of whether the row already existed or not - - *Note* that SQLite returns undefined for created, no matter if the row was created or updated. This is - because SQLite always runs INSERT OR IGNORE + UPDATE, in a single query, so there is no way to know - whether the row was inserted or not. - */ - static upsert(values: TInitAttributes, options?: UpsertOptions): Promise, - static insertOrUpdate(values: TInitAttributes, options?: UpsertOptions): Promise, - - /** - * Create and insert multiple instances in bulk. - * - The success handler is passed an array of instances, but please notice that these may not completely - represent the state of the rows in the DB. This is because MySQL and SQLite do not make it easy to - obtain - back automatically generated IDs and other default values in a way that can be mapped to multiple - records. To obtain Instances for the newly created values, you will need to query for them again. - * @param records List of objects (key/value pairs) to create instances from - */ - static bulkCreate( - records: TInitAttributes[], - options?: BulkCreateOptions): Promise, - - /** - * Truncate all instances of the model. This is a convenient method for Model.destroy({ truncate: true }). - */ - static truncate(options?: TruncateOptions): Promise, - - /** - * Delete multiple instances, or set their deletedAt timestamp to the current time if `paranoid` is enabled. - * @return Promise The number of destroyed rows - */ - static destroy(options?: DestroyOptions): Promise, - - /** - * Restore multiple instances if `paranoid` is enabled. - */ - static restore(options?: RestoreOptions): Promise, - - /** - * Update multiple instances that match the where options. The promise returns an array with one or two - * elements. The first element is always the number of affected rows, while the second element is the actual - affected rows (only supported in postgres with `options.returning` true.) - */ - static update( - values: $Shape, - options: UpdateOptions): Promise<[number, this[]]>, - - /** - * Run a describe query on the table. The result will be return to the listener as a hash of attributes and - * their types. - */ - static describe(): Promise, - - /** - * Unscope the model - */ - static unscoped(): Class, - - /** - * Add a hook to the model - * @param hookType - * @param name Provide a name for the hook function. It can be used to remove the hook later or to order - hooks based on some sort of priority system in the future. - * @param fn The hook function - * @alias hook - */ - static addHook(hookType: string, name: string, fn: Function): Class, - static addHook(hookType: string, fn: Function): Class, - static hook(hookType: string, name: string, fn: Function): Class, - static hook(hookType: string, fn: Function): Class, - - /** - * Remove hook from the model - * @param hookType - * @param name - */ - static removeHook(hookType: string, name: string): Class, - - /** - * Check whether the model has any hooks of this type - * @param hookType - * @alias hasHooks - */ - static hasHook(hookType: string): boolean, - static hasHooks(hookType: string): boolean, - - /** - * A hook that is run before validation - * @param name - * @param fn A callback function that is called with instance, options - */ - static beforeValidate( - name: string, - fn: AsyncFn2): void, - static beforeValidate(fn: AsyncFn2): void, - - /** - * A hook that is run after validation - * @param name - * @param fn A callback function that is called with instance, options - */ - static afterValidate( - name: string, - fn: AsyncFn2): void, - static afterValidate(fn: AsyncFn2): void, - - /** - * A hook that is run after validation - * @param name - * @param fn A callback function that is called with instance, options - */ - static validationFailed( - name: string, - fn: AsyncFn3): void, - static validationFailed(fn: AsyncFn3): void, - - /** - * A hook that is run before creating a single instance - * @param name - * @param fn A callback function that is called with attributes, options - */ - static beforeCreate( - name: string, - fn: AsyncFn2): void, - static beforeCreate(fn: AsyncFn2): void, - - /** - * A hook that is run after creating a single instance - * @param name - * @param fn A callback function that is called with attributes, options - */ - static afterCreate( - name: string, - fn: AsyncFn2): void, - static afterCreate(fn: AsyncFn2): void, - - /** - * A hook that is run before destroying a single instance - * @param name - * @param fn A callback function that is called with instance, options - * @alias beforeDelete - */ - static beforeDestroy( - name: string, - fn: AsyncFn2): void, - static beforeDestroy(fn: AsyncFn2): void, - static beforeDelete( - name: string, - fn: AsyncFn2): void, - static beforeDelete(fn: AsyncFn2): void, - - /** - * A hook that is run after destroying a single instance - * @param name - * @param fn A callback function that is called with instance, options - * @alias afterDelete - */ - static afterDestroy( - name: string, - fn: AsyncFn2): void, - static afterDestroy(fn: AsyncFn2): void, - static afterDelete( - name: string, - fn: AsyncFn2): void, - static afterDelete(fn: AsyncFn2): void, - - /** - * A hook that is run before updating a single instance - * @param name - * @param fn A callback function that is called with instance, options - */ - static beforeUpdate( - name: string, - fn: AsyncFn2): void, - static beforeUpdate(fn: AsyncFn2): void, - - /** - * A hook that is run after updating a single instance - * @param name - * @param fn A callback function that is called with instance, options - */ - static afterUpdate( - name: string, - fn: AsyncFn2): void, - static afterUpdate(fn: AsyncFn2): void, - - /** - * A hook that is run before upserting - * @param name - * @param fn A callback function that is called with attributes, options - */ - static beforeUpsert( - name: string, - fn: AsyncFn2): void, - static beforeUpsert(fn: AsyncFn2): void, - - /** - * A hook that is run after upserting - * @param name - * @param fn A callback function that is called with result of upsert(), options - */ - static afterUpsert( - name: string, - fn: AsyncFn2): void, - static afterUpsert(fn: AsyncFn2): void, - - /** - * A hook that is run before creating instances in bulk - * @param name - * @param fn A callback function that is called with instances, options - */ - static beforeBulkCreate( - name: string, - fn: AsyncFn2): void, - static beforeBulkCreate(fn: AsyncFn2): void, - - /** - * A hook that is run after creating instances in bulk - * @param name - * @param fn A callback function that is called with instances, options - * @name afterBulkCreate - */ - static afterBulkCreate( - name: string, - fn: AsyncFn2): void, - static afterBulkCreate(fn: AsyncFn2): void, - - /** - * A hook that is run before destroying instances in bulk - * @param name - * @param fn A callback function that is called with options - * @alias beforeBulkDelete - */ - static beforeBulkDestroy(name: string, fn: AsyncFn1): void, - static beforeBulkDestroy(fn: AsyncFn1): void, - static beforeBulkDelete(name: string, fn: AsyncFn1): void, - static beforeBulkDelete(fn: AsyncFn1): void, - - /* A hook that is run after destroying instances in bulk - * @param name - * @param fn A callback function that is called with options - * @alias afterBulkDelete - */ - static afterBulkDestroy(name: string, fn: AsyncFn1): void, - static afterBulkDestroy(fn: AsyncFn1): void, - static afterBulkDelete(name: string, fn: AsyncFn1): void, - static afterBulkDelete(fn: AsyncFn1): void, - - /** - * A hook that is run after updating instances in bulk - * @param name - * @param fn A callback function that is called with options - */ - static beforeBulkUpdate(name: string, fn: AsyncFn1): void, - static beforeBulkUpdate(fn: AsyncFn1): void, - - /** - * A hook that is run after updating instances in bulk - * @param name - * @param fn A callback function that is called with options - */ - static afterBulkUpdate(name: string, fn: AsyncFn1): void, - static afterBulkUpdate(fn: AsyncFn1): void, - - /** - * A hook that is run before a find (select) query - * @param name - * @param fn A callback function that is called with options - */ - static beforeFind(name: string, fn: AsyncFn1): void, - static beforeFind(fn: AsyncFn1): void, - - /** - * A hook that is run before a find (select) query, after any { include: {all: ...} } options are expanded - * @param name - * @param fn A callback function that is called with options - */ - static beforeFindAfterExpandIncludeAll(name: string, fn: AsyncFn1): void, - static beforeFindAfterExpandIncludeAll(fn: AsyncFn1): void, - - /** - * A hook that is run before a find (select) query, after all option parsing is complete - * @param name - * @param fn A callback function that is called with options - */ - static beforeFindAfterOptions(name: string, fn: AsyncFn1): void, - static beforeFindAfterOptions(fn: AsyncFn1): void, - - /** - * A hook that is run after a find (select) query - * @param name - * @param fn A callback function that is called with instance(s), options - */ - static afterFind( - name: string, - AsyncFn2): void, - static afterFind( - AsyncFn2): void, - - /** - * A hook that is run before a define call - * @param name - * @param fn A callback function that is called with attributes, options - */ - static beforeDefine( - name: string, - fn: AsyncFn2): void, - static beforeDefine(fn: AsyncFn2): void, - - /** - * A hook that is run after a define call - * @param name - * @param fn A callback function that is called with factory - */ - static afterDefine(name: string, fn: AsyncFn1>): void, - static afterDefine(fn: AsyncFn1>): void, - - /** - * A hook that is run before Sequelize() call - * @param name - * @param fn A callback function that is called with config, options - */ - static beforeInit(name: string, fn: AsyncFn2): void, - static beforeInit(fn: AsyncFn2): void, - - /** - * A hook that is run after Sequelize() call - * @param name - * @param fn A callback function that is called with sequelize - */ - static afterInit(name: string, fn: AsyncFn1): void, - static afterInit(fn: AsyncFn1): void, - - /** - * A hook that is run before Model.sync call - * @param name - * @param fn A callback function that is called with options passed to Model.sync - */ - static beforeSync(name: string, fn: AsyncFn1): void, - static beforeSync(fn: AsyncFn1): void, - - /** - * A hook that is run after Model.sync call - * @param name - * @param fn A callback function that is called with options passed to Model.sync - */ - static afterSync(name: string, fn: AsyncFn1): void, - static afterSync(fn: AsyncFn1): void, - - /** - * A hook that is run before sequelize.sync call - * @param name - * @param fn A callback function that is called with options passed to sequelize.sync - */ - static beforeBulkSync(name: string, fn: AsyncFn1): void, - static beforeBulkSync(fn: AsyncFn1): void, - - /** - * A hook that is run after sequelize.sync call - * @param name - * @param fn A callback function that is called with options passed to sequelize.sync - */ - static afterBulkSync(name: string, fn: AsyncFn1): void, - static afterBulkSync(fn: AsyncFn1): void, - - /** - * Creates an association between this (the source) and the provided target. The foreign key is added - * on the target. - - Example: `User.hasOne(Profile)`. This will add userId to the profile table. - * @param target The model that will be associated with hasOne relationship - * @param options Options for the association - */ - static hasOne>( - target: Class, - options?: AssociationOptionsHasOne): HasOne, - - /** - * Creates an association between this (the source) and the provided target. The foreign key is added on the - * source. - - Example: `Profile.belongsTo(User)`. This will add userId to the profile table. - * @param target The model that will be associated with hasOne relationship - * @param options Options for the association - */ - static belongsTo>( - target: Class, - options?: AssociationOptionsBelongsTo): BelongsTo, - - /** - * Create an association that is either 1:m or n:m. - * - ```js - // Create a 1:m association between user and project - User.hasMany(Project) - ``` - ```js - // Create a n:m association between user and project - User.hasMany(Project) - Project.hasMany(User) - ``` - By default, the name of the join table will be source+target, so in this case projectsusers. This can be - overridden by providing either a string or a Model as `through` in the options. If you use a through - model with custom attributes, these attributes can be set when adding / setting new associations in two - ways. Consider users and projects from before with a join table that stores whether the project has been - started yet: - ```js - var UserProjects = sequelize.define('userprojects', { - started: Sequelize.BOOLEAN - }) - User.hasMany(Project, { through: UserProjects }) - Project.hasMany(User, { through: UserProjects }) - ``` - ```js - jan.addProject(homework, { started: false }) // The homework project is not started yet - jan.setProjects([makedinner, doshopping], { started: true}) // Both shopping and dinner have been - started - ``` - - If you want to set several target instances, but with different attributes you have to set the - attributes on the instance, using a property with the name of the through model: - - ```js - p1.userprojects { - started: true - } - user.setProjects([p1, p2], {started: false}) // The default value is false, but p1 overrides that. - ``` - - Similarily, when fetching through a join table with custom attributes, these attributes will be - available as an object with the name of the through model. - ```js - user.getProjects().then(function (projects) { - var p1 = projects[0] - p1.userprojects.started // Is this project started yet? - }) - ``` - * @param target The model that will be associated with hasOne relationship - * @param options Options for the association - */ - static hasMany>( - target: Class, - options?: AssociationOptionsHasMany): HasMany, - - /** - * Create an N:M association with a join table - * - ```js - User.belongsToMany(Project) - Project.belongsToMany(User) - ``` - By default, the name of the join table will be source+target, so in this case projectsusers. This can be - overridden by providing either a string or a Model as `through` in the options. - - If you use a through model with custom attributes, these attributes can be set when adding / setting new - associations in two ways. Consider users and projects from before with a join table that stores whether - the project has been started yet: - ```js - var UserProjects = sequelize.define('userprojects', { - started: Sequelize.BOOLEAN - }) - User.belongsToMany(Project, { through: UserProjects }) - Project.belongsToMany(User, { through: UserProjects }) - ``` - ```js - jan.addProject(homework, { started: false }) // The homework project is not started yet - jan.setProjects([makedinner, doshopping], { started: true}) // Both shopping and dinner has been started - ``` - - If you want to set several target instances, but with different attributes you have to set the - attributes on the instance, using a property with the name of the through model: - - ```js - p1.userprojects { - started: true - } - user.setProjects([p1, p2], {started: false}) // The default value is false, but p1 overrides that. - ``` - - Similarily, when fetching through a join table with custom attributes, these attributes will be - available as an object with the name of the through model. - ```js - user.getProjects().then(function (projects) { - var p1 = projects[0] - p1.userprojects.started // Is this project started yet? - }) - ``` - * @param target The model that will be associated with hasOne relationship - * @param options Options for the association - */ - static belongsToMany< - TargetAttributes: Object, - TargetInitAttributes: Object, - Target: Model, - ThroughAttributes: Object, - Through: Model - >( - target: Class, - options: AssociationOptionsBelongsToMany - ): BelongsToMany< - TAttributes, TInitAttributes, this, - TargetAttributes, TargetInitAttributes, Target, - ThroughAttributes, Through - >, - - static getAssociations>(model: Class): Array>; - static getAssociationForAlias>(model: Class, alias: ?string): ?Association; - - static associations: {[name: string]: Association}, - static tableName: string, - static rawAttributes: {[name: string]: Attribute}, - static tableAttributes: {[name: string]: Attribute}, - static attributes: {[name: string]: Attribute}, - static primaryKeys: {[name: string]: Attribute}, - static primaryKeyAttributes: Array, - static primaryKeyAttribute: ?string, - static primaryKeyField?: string, - static uniqueKeys: {[idxName: string | false]: { - name: string | false, - column: string | false, - msg: ?string, - fields: Array, - }}, - static fieldRawAttributesMap: {[name: string]: string}, - static fieldAttributesMap: {[name: string]: string}, - - Model: Class, - - sequelize: Sequelize, - - /** - * Returns true if this instance has not yet been persisted to the database - */ - isNewRecord: boolean, - - /** - * Get an object representing the query for this instance, use with `options.where` - */ - where(): Object, - - /** - * Get the value of the underlying data value - */ - getDataValue(key: $Keys): any, - - /** - * Update the underlying data value - */ - setDataValue(key: $Keys, value: any): void, - - /** - * If no key is given, returns all values of the instance, also invoking virtual getters. - * - If key is given and a field or virtual getter is present for the key it will call that getter - else it - will return the value for key. - * @param options .plain If set to true, included instances will be returned as plain objects - */ - get(options: {plain: true, raw?: boolean, clone?: boolean}): TPlainAttributes, - get(key: $Keys, options?: {plain?: boolean, clone?: boolean, raw?: boolean}): any, - get(options?: {plain?: boolean, clone?: boolean, raw?: boolean}): TAttributes, - - /** - * Set is used to update values on the instance (the sequelize representation of the instance that is, - * remember that nothing will be persisted before you actually call `save`). In its most basic form `set` - will update a value stored in the underlying `dataValues` object. However, if a custom setter function - is defined for the key, that function will be called instead. To bypass the setter, you can pass `raw: - true` in the options object. - - If set is called with an object, it will loop over the object, and call set recursively for each key, - value pair. If you set raw to true, the underlying dataValues will either be set directly to the object - passed, or used to extend dataValues, if dataValues already contain values. - - When set is called, the previous value of the field is stored and sets a changed flag(see `changed`). - - Set can also be used to build instances for associations, if you have values for those. - When using set with associations you need to make sure the property key matches the alias of the - association while also making sure that the proper include options have been set (from .build() or - .find()) - - If called with a dot.seperated key on a JSON/JSONB attribute it will set the value nested and flag the - entire object as changed. - * @param options .raw If set to true, field and virtual setters will be ignored - * @param options .reset Clear all previously set data values - */ - set(key: $Keys, value: any, options?: InstanceSetOptions): this, - set(keys: $Shape, options?: InstanceSetOptions): this, - setAttributes(key: $Keys, value: any, options?: InstanceSetOptions): this, - setAttributes(keys: $Shape, options?: InstanceSetOptions): this, - - /** - * If changed is called with a string it will return a boolean indicating whether the value of that key in - * `dataValues` is different from the value in `_previousDataValues`. - - If changed is called without an argument, it will return an array of keys that have changed. - - If changed is called without an argument and no keys have changed, it will return `false`. - */ - changed(key: $Keys): boolean, - changed(): boolean | Array<$Keys>, - - /** - * Returns the previous value for key from `_previousDataValues`. - */ - previous(key: $Keys): any, - - /** - * Validate this instance, and if the validation passes, persist it to the database. - * - On success, the callback will be called with this instance. On validation error, the callback will be - called with an instance of `Sequelize.ValidationError`. This error will have a property for each of the - fields for which validation failed, with the error message for that field. - */ - save(options?: InstanceSaveOptions): Promise, - - /** - * Refresh the current instance in-place, i.e. update the object with current data from the DB and return - * the same object. This is different from doing a `find(Instance.id)`, because that would create and - return a new instance. With this method, all references to the Instance are updated with the new data - and no new objects are created. - */ - reload(options?: AnyFindOptions): Promise, - - /** - * Validate the attribute of this instance according to validation rules set in the model definition. - * - Emits null if and only if validation successful; otherwise an Error instance containing - { field name : [error msgs] } entries. - * @param options .skip An array of strings. All properties that are in this array will not be validated - */ - validate(options?: { - skip?: $Keys[] - }): Promise, - - /** - * This is the same as calling `set` and then calling `save`. - */ - update( - key: $Keys, - value: any, - options?: InstanceUpdateOptions): Promise, - update(keys: $Shape, options?: InstanceUpdateOptions): Promise, - updateAttributes( - key: $Keys, - value: any, - options?: InstanceUpdateOptions): Promise, - updateAttributes(keys: $Shape, options?: InstanceUpdateOptions): Promise, - - /** - * Destroy the row corresponding to this instance. Depending on your setting for paranoid, the row will - * either be completely deleted, or have its deletedAt timestamp set to the current time. - */ - destroy(options?: InstanceDestroyOptions): Promise, - - /** - * Restore the row corresponding to this instance. Only available for paranoid models. - */ - restore(options?: InstanceRestoreOptions): Promise, - - /** - * Increment the value of one or more columns. This is done in the database, which means it does not use - * the values currently stored on the Instance. The increment is done using a - ```sql - SET column = column + X - ``` - query. To get the correct value after an increment into the Instance you should do a reload. - - ```js - instance.increment('number') // increment number by 1 - instance.increment(['number', 'count'], { by: 2 }) // increment number and count by 2 - instance.increment({ answer: 42, tries: 1}, { by: 2 }) // increment answer by 42, and tries by 1. - // `by` is ignored, since each column has its own - // value - ``` - * @param fields If a string is provided, that column is incremented by the value of `by` given in options. - If an array is provided, the same is true for each column. - If and object is provided, each column is incremented by the value given. - */ - increment( - fields: $Keys | $Keys[] | {[key: $Keys]: number}, - options?: InstanceIncrementDecrementOptions): Promise, - - /** - * Decrement the value of one or more columns. This is done in the database, which means it does not use - * the values currently stored on the Instance. The decrement is done using a - ```sql - SET column = column - X - ``` - query. To get the correct value after an decrement into the Instance you should do a reload. - - ```js - instance.decrement('number') // decrement number by 1 - instance.decrement(['number', 'count'], { by: 2 }) // decrement number and count by 2 - instance.decrement({ answer: 42, tries: 1}, { by: 2 }) // decrement answer by 42, and tries by 1. - // `by` is ignored, since each column has its own - // value - ``` - * @param fields If a string is provided, that column is decremented by the value of `by` given in options. - If an array is provided, the same is true for each column. - If and object is provided, each column is decremented by the value given - */ - decrement( - fields: $Keys | $Keys[] | {[key: $Keys]: number}, - options?: InstanceIncrementDecrementOptions): Promise, - - /** - * Check whether all values of this and `other` Instance are the same - */ - equals(other: Model): boolean, - - /** - * Check if this is equal to one of `others` by calling equals - */ - equalsOneOf(others: Model[]): boolean, - - /** - * Convert the instance to a JSON representation. Proxies to calling `get` with no keys. This means get all - * values gotten from the DB, and apply all custom getters. - */ - toJSON(): TPlainAttributes, - } - - - - /** - * Most of the methods accept options and use only the logger property of the options. That's why the most used - * interface type for options in a method is separated here as another interface. - */ - declare export type QueryInterfaceOptions = { - /** - * A function that gets executed while running the query to log the sql. - */ - logging?: boolean | Function - } - - declare export type AddUniqueConstraintOptions = { - type: 'unique', - name?: string - } - - declare export type AddDefaultConstraintOptions = { - type: 'default', - name?: string, - defaultValue?: any - } - - declare export type AddCheckConstraintOptions = { - type: 'check', - name?: string, - where?: WhereOptions - } - - declare export type AddPrimaryKeyConstraintOptions = { - type: 'primary key', - name?: string - } - - declare export type AddForeignKeyConstraintOptions = { - type: 'foreign key', - name?: string, - references?: { - table: string, - field: string - }, - onDelete: string, - onUpdate: string - } - - declare export type AddConstraintOptions = - AddUniqueConstraintOptions | - AddDefaultConstraintOptions | - AddCheckConstraintOptions | - AddPrimaryKeyConstraintOptions | - AddForeignKeyConstraintOptions; - - - /** - * The interface that Sequelize uses to talk to all databases. - * - This interface is available through sequelize.QueryInterface. It should not be commonly used, but it's - referenced anyway, so it can be used. - */ - declare export interface QueryInterface { - /** - * Returns the dialect-specific sql generator. - * - We don't have a definition for the QueryGenerator, because I doubt it is commonly in use separately. - */ - QueryGenerator: any, - - /** - * Returns the current sequelize instance. - */ - sequelize: Sequelize, - - /** - * Queries the schema (table list). - * @param schema The schema to query. Applies only to Postgres. - */ - createSchema(schema?: string, options?: QueryInterfaceOptions): Promise, - - /** - * Drops the specified schema (table). - * @param schema The schema to query. Applies only to Postgres. - */ - dropSchema(schema?: string, options?: QueryInterfaceOptions): Promise, - - /** - * Drops all tables. - */ - dropAllSchemas(options?: QueryInterfaceOptions): Promise, - - /** - * Queries all table names in the database. - * @param options - */ - showAllSchemas(options?: QueryOptions): Promise, - - /** - * Return database version - */ - databaseVersion(options?: QueryInterfaceOptions): Promise, - - /** - * Creates a table with specified attributes. - * @param tableName Name of table to create - * @param attributes Hash of attributes, key is attribute name, value is data type - * @param options Query options. - */ - createTable( - tableName: string | { - schema?: string, - tableName?: string - }, - attributes: DefineAttributes, - options?: QueryOptions): Promise, - - /** - * Drops the specified table. - * @param tableName Table name. - * @param options Query options, particularly "force". - */ - dropTable(tableName: string, options?: QueryOptions): Promise, - - /** - * Drops all tables. - * @param options - */ - dropAllTables(options?: QueryOptions): Promise, - - /** - * Drops all defined enums - * @param options - */ - dropAllEnums(options?: QueryOptions): Promise, - - /** - * Renames a table - */ - renameTable( - before: string, - after: string, - options?: QueryInterfaceOptions): Promise, - - /** - * Returns all tables - */ - showAllTables(options?: QueryOptions): Promise, - - /** - * Describe a table - */ - describeTable( - tableName: string | { - schema?: string, - tableName?: string - }, - options?: string | { - schema?: string, - schemaDelimeter?: string, - logging?: boolean | Function - }): Promise, - - /** - * Adds a new column to a table - */ - addColumn( - table: string, - key: string, - attribute: DefineAttributeColumnOptions | DataTypeAbstract, - options?: QueryInterfaceOptions): Promise, - - /** - * Removes a column from a table - */ - removeColumn( - table: string, - attribute: string, - options?: QueryInterfaceOptions): Promise, - - /** - * Changes a column - */ - changeColumn( - tableName: string | { - schema?: string, - tableName?: string - }, - attributeName: string, - dataTypeOrOptions?: string | DataTypeAbstract | DefineAttributeColumnOptions, - options?: QueryInterfaceOptions): Promise, - - /** - * Renames a column - */ - renameColumn( - tableName: string | { - schema?: string, - tableName?: string - }, - attrNameBefore: string, - attrNameAfter: string, - options?: QueryInterfaceOptions): Promise, - - /** - * Adds a new index to a table - */ - addIndex( - tableName: string | Object, - options?: { - fields: Array, - unique?: boolean, - using?: string, - type?: IndexType, - name?: string, - where?: WhereOptions, - } - ): Promise, - - /** - * Shows the index of a table - */ - showIndex(tableName: string | Object, options?: QueryOptions): Promise, - - /** - * Put a name to an index - */ - nameIndexes(indexes: string[], rawTablename: string): Promise, - - /** - * Returns all foreign key constraints of a table - */ - getForeignKeysForTables(tableNames: string, options?: QueryInterfaceOptions): Promise, - - /** - * Removes an index of a table - */ - removeIndex( - tableName: string, - indexNameOrAttributes: string[] | string, - options?: QueryInterfaceOptions): Promise, - - /** - * Adds constraints to a table - */ - addConstraint( - tableName: string, - attributes: string[], - options?: AddConstraintOptions | QueryInterfaceOptions): Promise, - - /** - * Removes constraints from a table - */ - removeConstraint( - tableName: string, - constraintName: string, - options?: QueryInterfaceOptions): Promise, - - /** - * Inserts a new record - */ - insert( - instance: Model, - tableName: string, - values: Object, - options?: QueryOptions): Promise, - - /** - * Inserts or Updates a record in the database - */ - upsert( - tableName: string, - values: Object, - updateValues: Object, - model: Class>, - options?: QueryOptions): Promise, - - /** - * Inserts multiple records at once - */ - bulkInsert( - tableName: string, - records: Object[], - options?: QueryOptions, - attributes?: string[] | string): Promise, - - /** - * Updates a row - */ - update( - instance: Model, - tableName: string, - values: Object, - identifier: Object, - options?: QueryOptions): Promise, - - /** - * Updates multiple rows at once - */ - bulkUpdate( - tableName: string, - values: Object, - identifier: Object, - options?: QueryOptions, - attributes?: string[] | string): Promise, - - /** - * Deletes a row - */ - delete( - instance: Model, - tableName: string, - identifier: Object, - options?: QueryOptions): Promise, - - /** - * Deletes multiple rows at once - */ - bulkDelete( - tableName: string, - identifier: Object, - options?: QueryOptions, - model?: Class>): Promise, - - /** - * Returns selected rows - */ - select( - model: Class>, - tableName: string, - options?: QueryOptions): Promise, - - /** - * Increments a row value - */ - increment( - instance: Model, - tableName: string, - values: Object, - identifier: Object, - options?: QueryOptions): Promise, - - /** - * Selects raw without parsing the string into an object - */ - rawSelect( - tableName: string, - options: QueryOptions, - attributeSelector: string | string[], - model?: Class>): Promise, - - /** - * Postgres only. Creates a trigger on specified table to call the specified function with supplied - * parameters. - */ - createTrigger( - tableName: string, - triggerName: string, - timingType: string, - fireOnArray: any[], - functionName: string, - functionParams: any[], - optionsArray: string[], - options?: QueryInterfaceOptions): Promise, - - /** - * Postgres only. Drops the specified trigger. - */ - dropTrigger( - tableName: string, - triggerName: string, - options?: QueryInterfaceOptions): Promise, - - /** - * Postgres only. Renames a trigger - */ - renameTrigger( - tableName: string, - oldTriggerName: string, - newTriggerName: string, - options?: QueryInterfaceOptions): Promise, - - /** - * Postgres only. Create a function - */ - createFunction( - functionName: string, - params: any[], - returnType: string, - language: string, - body: string, - options?: QueryOptions): Promise, - - /** - * Postgres only. Drops a function - */ - dropFunction( - functionName: string, - params: any[], - options?: QueryInterfaceOptions): Promise, - - /** - * Postgres only. Rename a function - */ - renameFunction( - oldFunctionName: string, - params: any[], - newFunctionName: string, - options?: QueryInterfaceOptions): Promise, - - /** - * Escape an identifier (e.g. a table or attribute name). If force is true, the identifier will be quoted - * even if the `quoteIdentifiers` option is false. - */ - quoteIdentifier(identifier: string, force: boolean): string, - - /** - * Escape a table name - */ - quoteTable(identifier: string): string, - - /** - * Split an identifier into .-separated tokens and quote each part. If force is true, the identifier will be - * quoted even if the `quoteIdentifiers` option is false. - */ - quoteIdentifiers(identifiers: string, force: boolean): string, - - /** - * Escape a value (e.g. a string, number or date) - */ - escape(value?: string | number | Date): string, - - /** - * Set option for autocommit of a transaction - */ - setAutocommit( - transaction: Transaction, - value: boolean, - options?: QueryOptions): Promise, - - /** - * Set the isolation level of a transaction - */ - setIsolationLevel( - transaction: Transaction, - value: string, - options?: QueryOptions): Promise, - - /** - * Begin a new transaction - */ - startTransaction( - transaction: Transaction, - options?: QueryOptions): Promise, - - /** - * Defer constraints - */ - deferConstraints( - transaction: Transaction, - options?: QueryOptions): Promise, - - /** - * Commit an already started transaction - */ - commitTransaction( - transaction: Transaction, - options?: QueryOptions): Promise, - - /** - * Rollback ( revert ) a transaction that has'nt been commited - */ - rollbackTransaction( - transaction: Transaction, - options?: QueryOptions): Promise - } - - declare export type QueryTypes = { - SELECT: string, - INSERT: string, - UPDATE: string, - BULKUPDATE: string, - BULKDELETE: string, - DELETE: string, - UPSERT: string, - VERSION: string, - SHOWTABLES: string, - SHOWINDEXES: string, - DESCRIBE: string, - RAW: string, - FOREIGNKEYS: string - } - - - /** - * General column options - * @see Define - * @see AssociationForeignKeyOptions - */ - declare export type ColumnOptions = { - /** - * If false, the column will have a NOT NULL constraint, and a not null validation will be run before an - * instance is saved. - */ - allowNull?: boolean, - - /** - * If set, sequelize will map the attribute name to a different name in the database - */ - field?: string, - - /** - * A literal default value, a JavaScript function, or an SQL function (see `sequelize.fn`) - */ - defaultValue?: any - } - - - /** - * References options for the column's attributes - * @see AttributeColumnOptions - */ - declare export type DefineAttributeColumnReferencesOptions = { - /** - * If this column references another table, provide it here as a Model, or a string - */ - model: string | Class>, - - /** - * The column of the foreign table that this column references - */ - key?: string, - - /** - * When to check for the foreign key constraing - * - PostgreSQL only - */ - deferrable?: DeferrableInitiallyDeferred | - DeferrableInitiallyImmediate | - DeferrableNot | - DeferrableSetDeferred | - DeferrableSetImmediate - } - - - /** - * Column options for the model schema attributes - * @see Attributes - */ - declare export type DefineAttributeColumnOptions = { - /** - * A string or a data type - */ - type: string | DataTypeAbstract, - - /** - * If true, the column will get a unique constraint. If a string is provided, the column will be part of a - * composite unique index. If multiple columns have the same string, they will be part of the same unique - index - */ - unique?: boolean | string | { - name: string, - msg: string - }, - - /** - * Primary key flag - */ - primaryKey?: boolean, - - /** - * Is this field an auto increment field - */ - autoIncrement?: boolean, - - /** - * Comment for the database - */ - comment?: string, - - /** - * An object with reference configurations - */ - references?: string | Model | DefineAttributeColumnReferencesOptions, - - /** - * What should happen when the referenced key is updated. One of CASCADE, RESTRICT, SET DEFAULT, SET NULL or - * NO ACTION - */ - onUpdate?: string, - - /** - * What should happen when the referenced key is deleted. One of CASCADE, RESTRICT, SET DEFAULT, SET NULL or - * NO ACTION - */ - onDelete?: string, - - /** - * Provide a custom getter for this column. Use `this.getDataValue(String)` to manipulate the underlying - * values. - */ - get?: () => any, - - /** - * Provide a custom setter for this column. Use `this.setDataValue(String, Value)` to manipulate the - * underlying values. - */ - set?: (val: any) => void, - - /** - * An object of validations to execute for this column every time the model is saved. Can be either the - * name of a validation provided by validator.js, a validation function provided by extending validator.js - (see the - `DAOValidator` property for more details), or a custom validation function. Custom validation functions - are called with the value of the field, and can possibly take a second callback argument, to signal that - they are asynchronous. If the validator is sync, it should throw in the case of a failed validation, it - it is async, the callback should be called with the error text. - */ - validate?: DefineValidateOptions, - - /** - * Usage in object notation - * - ```js - sequelize.define('model', { - states: { - type: Sequelize.ENUM, - values: ['active', 'pending', 'deleted'] - } - }) - ``` - */ - values?: string[] - } & ColumnOptions - - - - /** - * Interface for Attributes provided for a column - * @see Sequelize.define - */ - declare export type DefineAttributes = { - [name: string]: string | DataTypeAbstract | DefineAttributeColumnOptions - } - - - /** - * Interface for query options - * @see Options - */ - declare export type QueryOptions = { - /** - * If true, sequelize will not try to format the results of the query, or build an instance of a model from - * the result - */ - raw?: boolean, - - /** - * The type of query you are executing. The query type affects how results are formatted before they are - * passed back. The type is a string, but `Sequelize.QueryTypes` is provided as convenience shortcuts. - */ - type?: string, - - /** - * If true, transforms objects with `.` separated property names into nested objects using - * [dottie.js](https://github.com/mickhansen/dottie.js). For example { 'user.username': 'john' } becomes - { user: { username: 'john' }}. When `nest` is true, the query type is assumed to be `'SELECT'`, - unless otherwise specified - - Defaults to false - */ - nest?: boolean, - - /** - * Sets the query type to `SELECT` and return a single row - */ - plain?: boolean, - - /** - * Either an object of named parameter replacements in the format `:param` or an array of unnamed - * replacements to replace `?` in your SQL. - */ - replacements?: Object | $ReadOnlyArray, - - /** - * Either an object of named bind parameter in the format `$param` or an array of unnamed - * bind parameter to replace `$1`, `$2`, ... in your SQL. - */ - bind?: Object | $ReadOnlyArray, - - /** - * Force the query to use the write pool, regardless of the query type. - * - Defaults to false - */ - useMaster?: boolean, - - /** - * A function that gets executed while running the query to log the sql. - */ - logging?: boolean | Function, - - /** - * A sequelize instance used to build the return instance - */ - instance?: Model, - - /** - * A sequelize model used to build the returned model instances (used to be called callee) - */ - model?: Class>, - - /** - * Set of flags that control when a query is automatically retried. - */ - retry?: RetryOptions, - - /** - * If false do not prepend the query with the search_path (Postgres only) - */ - supportsSearchPath?: boolean, - - /** - * Map returned fields to model's fields if `options.model` or `options.instance` is present. - * Mapping will occur before building the model instance. - */ - mapToModel?: boolean, - fieldMap?: { - [key: string]: string - } - } & SearchPathOptions & ReturningOptions - - - - /** - * Model validations, allow you to specify format/content/inheritance validations for each attribute of the - * model. - - Validations are automatically run on create, update and save. You can also call validate() to manually - validate an instance. - - The validations are implemented by validator.js. - */ - declare export type DefineValidateOptions = { - /** - * is: ["^[a-z]+$",'i'] // will only allow letters - * is: /^[a-z]+$/i // same as the previous example using real RegExp - */ - is?: string | $ReadOnlyArray| RegExp | { - msg: string, - args: string | $ReadOnlyArray| RegExp - }, - - /** - * not: ["[a-z]",'i'] // will not allow letters - */ - not?: string | $ReadOnlyArray| RegExp | { - msg: string, - args: string | $ReadOnlyArray| RegExp - }, - - /** - * checks for email format (foo@bar.com) - */ - isEmail?: boolean | { - msg: string - }, - - /** - * checks for url format (http://foo.com) - */ - isUrl?: boolean | { - msg: string - }, - - /** - * checks for IPv4 (129.89.23.1) or IPv6 format - */ - isIP?: boolean | { - msg: string - }, - - /** - * checks for IPv4 (129.89.23.1) - */ - isIPv4?: boolean | { - msg: string - }, - - /** - * checks for IPv6 format - */ - isIPv6?: boolean | { - msg: string - }, - - /** - * will only allow letters - */ - isAlpha?: boolean | { - msg: string - }, - - /** - * will only allow alphanumeric characters, so "_abc" will fail - */ - isAlphanumeric?: boolean | { - msg: string - }, - - /** - * will only allow numbers - */ - isNumeric?: boolean | { - msg: string - }, - - /** - * checks for valid integers - */ - isInt?: boolean | { - msg: string - }, - - /** - * checks for valid floating point numbers - */ - isFloat?: boolean | { - msg: string - }, - - /** - * checks for any numbers - */ - isDecimal?: boolean | { - msg: string - }, - - /** - * checks for lowercase - */ - isLowercase?: boolean | { - msg: string - }, - - /** - * checks for uppercase - */ - isUppercase?: boolean | { - msg: string - }, - - /** - * won't allow null - */ - notNull?: boolean | { - msg: string - }, - - /** - * only allows null - */ - isNull?: boolean | { - msg: string - }, - - /** - * don't allow empty strings - */ - notEmpty?: boolean | { - msg: string - }, - - /** - * only allow a specific value - */ - equals?: string | { - msg: string - }, - - /** - * force specific substrings - */ - contains?: string | { - msg: string - }, - - /** - * check the value is not one of these - */ - notIn?: string[][] | { - msg: string, - args: string[][] - }, - - /** - * check the value is one of these - */ - isIn?: string[][] | { - msg: string, - args: string[][] - }, - - /** - * don't allow specific substrings - */ - notContains?: string[] | string | { - msg: string, - args: string[] | string - }, - - /** - * only allow values with length between 2 and 10 - */ - len?: [number, number] | { - msg: string, - args: [number, number] - }, - - /** - * only allow uuids - */ - isUUID?: 3 | - 4 | - 5 | - 'all' | - { - msg: string, - args: number - }, - - /** - * only allow date strings - */ - isDate?: boolean | { - msg: string, - args: boolean - }, - - /** - * only allow date strings after a specific date - */ - isAfter?: string | { - msg: string, - args: string - }, - - /** - * only allow date strings before a specific date - */ - isBefore?: string | { - msg: string, - args: string - }, - - /** - * only allow values - */ - max?: number | { - msg: string, - args: number - }, - - /** - * only allow values>= 23 - */ - min?: number | { - msg: string, - args: number - }, - - /** - * only allow arrays - */ - isArray?: boolean | { - msg: string, - args: boolean - }, - - /** - * check for valid credit card numbers - */ - isCreditCard?: boolean | { - msg: string, - args: boolean - }, [name: string]: any - } - - declare export type IndexType = 'UNIQUE' | 'FULLTEXT' | 'SPATIAL' - - declare export type DefineIndexOptions = { - /** - * The index type - */ - indicesType?: IndexType, - - /** - * The name of the index. Default is __ - */ - indexName?: string, - - /** - * For FULLTEXT columns set your parser - */ - parser?: string, - - /** - * Set a type for the index, e.g. BTREE. See the documentation of the used dialect - */ - indexType?: string, - - /** - * A function that receives the sql query, e.g. console.log - */ - logging?: Function, - - /** - * A hash of attributes to limit your index(Filtered Indexes - MSSQL & PostgreSQL only) - */ - where?: WhereOptions - } - - declare export type IndexMethod = 'BTREE' | 'HASH' | 'GIST' | 'GIN' - - /** - * Interface for indexes property in DefineOptions - * @see DefineOptions - */ - declare export type DefineIndexesOptions = { - /** - * The name of the index. Defaults to model name + _ + fields concatenated - */ - name?: string, - - /** - * Index type. Only used by mysql. One of `UNIQUE`, `FULLTEXT` and `SPATIAL` - */ - index?: IndexType, - - /** - * The method to create the index by (`USING` statement in SQL). BTREE and HASH are supported by mysql and - * postgres, and postgres additionally supports GIST and GIN. - */ - method?: IndexMethod, - - /** - * Should the index by unique? Can also be triggered by setting type to `UNIQUE` - * - Defaults to false - */ - unique?: boolean, - - /** - * PostgreSQL will build the index without taking any write locks. Postgres only - * - Defaults to false - */ - concurrently?: boolean, - - /** - * An array of the fields to index. Each field can either be a string containing the name of the field, - * a sequelize object (e.g `sequelize.fn`), or an object with the following attributes: `attribute` - (field name), `length` (create a prefix index of length chars), `order` (the direction the column - should be sorted in), `collate` (the collation (sort order) for the column) - */ - fields?: $ReadOnlyArray, - - /** - * Method the index should use, for example 'gin' index. - */ - using?: string, - - /** - * Operator that should be used by gin index, see Built-in GIN Operator Classes - */ - operator?: string, - - /** - * Condition for partioal index - */ - where?: WhereOptions - } - - - /** - * Interface for name property in DefineOptions - * @see DefineOptions - */ - declare export type DefineNameOptions = { - /** - * Singular model name - */ - singular?: string, - - /** - * Plural model name - */ - plural?: string - } - - - /** - * Interface for getterMethods in DefineOptions - * @see DefineOptions - */ - declare export type DefineGetterMethodsOptions = { - [name: string]: () => any - } - - - /** - * Interface for setterMethods in DefineOptions - * @see DefineOptions - */ - declare export type DefineSetterMethodsOptions = { - [name: string]: (val: any) => void - } - - - /** - * Interface for Define Scope Options - * @see DefineOptions - */ - declare export type DefineScopeOptions = { - [scopeName: string]: AnyFindOptions | Function - } - - - /** - * Options for model definition - * @see Sequelize.define - */ - declare export type DefineOptions> = { - /** - * Define the default search scope to use for this model. Scopes have the same form as the options passed to - * find / findAll. - */ - defaultScope?: AnyFindOptions, - - /** - * More scopes, defined in the same way as defaultScope above. See `Model.scope` for more information about - * how scopes are defined, and what you can do with them - */ - scopes?: DefineScopeOptions, - - /** - * Don't persits null values. This means that all columns with null values will not be saved. - */ - omitNull?: boolean, - - /** - * Adds createdAt and updatedAt timestamps to the model. Default true. - */ - timestamps?: boolean, - - /** - * Calling destroy will not delete the model, but instead set a deletedAt timestamp if this is true. Needs - * timestamps=true to work. Default false. - */ - paranoid?: boolean, - - /** - * Converts all camelCased columns to underscored if true. Default false. - */ - underscored?: boolean, - - /** - * Converts camelCased model names to underscored tablenames if true. Default false. - */ - underscoredAll?: boolean, - - /** - * Indicates if the model's table has a trigger associated with it. Default false. - */ - hasTrigger?: boolean, - - /** - * If freezeTableName is true, sequelize will not try to alter the DAO name to get the table name. - * Otherwise, the dao name will be pluralized. Default false. - */ - freezeTableName?: boolean, - - /** - * An object with two attributes, `singular` and `plural`, which are used when this model is associated to - * others. - */ - name?: DefineNameOptions, - - /** - * Indexes for the provided database table - */ - indexes?: DefineIndexesOptions[], - - /** - * Override the name of the createdAt column if a string is provided, or disable it if false. Timestamps - * must be true. Not affected by underscored setting. - */ - createdAt?: string | boolean, - - /** - * Override the name of the deletedAt column if a string is provided, or disable it if false. Timestamps - * must be true. Not affected by underscored setting. - */ - deletedAt?: string | boolean, - - /** - * Override the name of the updatedAt column if a string is provided, or disable it if false. Timestamps - * must be true. Not affected by underscored setting. - */ - updatedAt?: string | boolean, - - /** - * Defaults to pluralized model name, unless freezeTableName is true, in which case it uses model name - * verbatim - */ - tableName?: string, - - /** - * Provide getter functions that work like those defined per column. If you provide a getter method with - * the - same name as a column, it will be used to access the value of that column. If you provide a name that - does not match a column, this function will act as a virtual getter, that can fetch multiple other - values - */ - getterMethods?: DefineGetterMethodsOptions, - - /** - * Provide setter functions that work like those defined per column. If you provide a setter method with - * the - same name as a column, it will be used to update the value of that column. If you provide a name that - does not match a column, this function will act as a virtual setter, that can act on and set other - values, but will not be persisted - */ - setterMethods?: DefineSetterMethodsOptions, - - /** - * Provide functions that are added to each instance (DAO). If you override methods provided by sequelize, - * you can access the original method using `this.constructor.super_.prototype`, e.g. - `this.constructor.super_.prototype.toJSON.apply(this, arguments)` - */ - instanceMethods?: Object, - - /** - * Provide functions that are added to the model (Model). If you override methods provided by sequelize, - * you can access the original method using `this.constructor.prototype`, e.g. - `this.constructor.prototype.find.apply(this, arguments)` - */ - classMethods?: Object, - schema?: string, - - /** - * You can also change the database engine, e.g. to MyISAM. InnoDB is the default. - */ - engine?: string, - charset?: string, - - /** - * Finaly you can specify a comment for the table in MySQL and PG - */ - comment?: string, - collate?: string, - - /** - * Set the initial AUTO_INCREMENT value for the table in MySQL. - */ - initialAutoIncrement?: string, - - /** - * An object of hook function that are called before and after certain lifecycle events. - * The possible hooks are: beforeValidate, afterValidate, beforeBulkCreate, beforeBulkDestroy, - beforeBulkUpdate, beforeCreate, beforeDestroy, beforeUpdate, afterCreate, afterDestroy, afterUpdate, - afterBulkCreate, afterBulkDestory and afterBulkUpdate. See Hooks for more information about hook - functions and their signatures. Each property can either be a function, or an array of functions. - */ - hooks?: HooksDefineOptions, - - /** - * An object of model wide validations. Validations have access to all model values via `this`. If the - * validator function takes an argument, it is asumed to be async, and is called with a callback that - accepts an optional error. - */ - validate?: DefineValidateOptions, - - /** - * Enable optimistic locking. When enabled, sequelize will add a version count attribute - * to the model and throw an OptimisticLockingError error when stale instances are saved. - Set to true or a string with the attribute name you want to use to enable. - */ - version?: boolean | string - } - - /** - * @see Model.options - */ - declare export type ResolvedDefineOptions> = { - /** - * Define the default search scope to use for this model. Scopes have the same form as the options passed to - * find / findAll. - */ - defaultScope: AnyFindOptions, - - /** - * More scopes, defined in the same way as defaultScope above. See `Model.scope` for more information about - * how scopes are defined, and what you can do with them - */ - scopes: DefineScopeOptions, - - /** - * Don't persits null values. This means that all columns with null values will not be saved. - */ - omitNull: boolean, - - /** - * Adds createdAt and updatedAt timestamps to the model. Default true. - */ - timestamps: boolean, - - /** - * Calling destroy will not delete the model, but instead set a deletedAt timestamp if this is true. Needs - * timestamps=true to work. Default false. - */ - paranoid: boolean, - - /** - * Converts all camelCased columns to underscored if true. Default false. - */ - underscored: boolean, - - /** - * Converts camelCased model names to underscored tablenames if true. Default false. - */ - underscoredAll: boolean, - - /** - * Indicates if the model's table has a trigger associated with it. Default false. - */ - hasTrigger?: boolean, - - /** - * If freezeTableName is true, sequelize will not try to alter the DAO name to get the table name. - * Otherwise, the dao name will be pluralized. Default false. - */ - freezeTableName: boolean, - - /** - * An object with two attributes, `singular` and `plural`, which are used when this model is associated to - * others. - */ - name: { - singular: string, - plural: string, - }, - - /** - * Indexes for the provided database table - */ - indexes: DefineIndexesOptions[], - - /** - * Override the name of the createdAt column if a string is provided, or disable it if false. Timestamps - * must be true. Not affected by underscored setting. - */ - createdAt?: string | boolean, - - /** - * Override the name of the deletedAt column if a string is provided, or disable it if false. Timestamps - * must be true. Not affected by underscored setting. - */ - deletedAt?: string | boolean, - - /** - * Override the name of the updatedAt column if a string is provided, or disable it if false. Timestamps - * must be true. Not affected by underscored setting. - */ - updatedAt?: string | boolean, - - /** - * Defaults to pluralized model name, unless freezeTableName is true, in which case it uses model name - * verbatim - */ - tableName?: string, - - /** - * Provide getter functions that work like those defined per column. If you provide a getter method with - * the - same name as a column, it will be used to access the value of that column. If you provide a name that - does not match a column, this function will act as a virtual getter, that can fetch multiple other - values - */ - getterMethods?: DefineGetterMethodsOptions, - - /** - * Provide setter functions that work like those defined per column. If you provide a setter method with - * the - same name as a column, it will be used to update the value of that column. If you provide a name that - does not match a column, this function will act as a virtual setter, that can act on and set other - values, but will not be persisted - */ - setterMethods?: DefineSetterMethodsOptions, - - /** - * Provide functions that are added to each instance (DAO). If you override methods provided by sequelize, - * you can access the original method using `this.constructor.super_.prototype`, e.g. - `this.constructor.super_.prototype.toJSON.apply(this, arguments)` - */ - instanceMethods?: Object, - - /** - * Provide functions that are added to the model (Model). If you override methods provided by sequelize, - * you can access the original method using `this.constructor.prototype`, e.g. - `this.constructor.prototype.find.apply(this, arguments)` - */ - classMethods?: Object, - schema: ?string, - schemaDelimeter: string, - - /** - * You can also change the database engine, e.g. to MyISAM. InnoDB is the default. - */ - engine?: string, - charset?: string, - - /** - * Finaly you can specify a comment for the table in MySQL and PG - */ - comment?: string, - collate?: string, - - /** - * Set the initial AUTO_INCREMENT value for the table in MySQL. - */ - initialAutoIncrement?: string, - - /** - * An object of hook function that are called before and after certain lifecycle events. - * The possible hooks are: beforeValidate, afterValidate, beforeBulkCreate, beforeBulkDestroy, - beforeBulkUpdate, beforeCreate, beforeDestroy, beforeUpdate, afterCreate, afterDestroy, afterUpdate, - afterBulkCreate, afterBulkDestory and afterBulkUpdate. See Hooks for more information about hook - functions and their signatures. Each property can either be a function, or an array of functions. - */ - hooks: HooksDefineOptions, - - /** - * An object of model wide validations. Validations have access to all model values via `this`. If the - * validator function takes an argument, it is asumed to be async, and is called with a callback that - accepts an optional error. - */ - validate: DefineValidateOptions, - - /** - * Enable optimistic locking. When enabled, sequelize will add a version count attribute - * to the model and throw an OptimisticLockingError error when stale instances are saved. - Set to true or a string with the attribute name you want to use to enable. - */ - version?: boolean | string, - - sequelize: Sequelize, - } - - - /** - * Sync Options - * @see Sequelize.sync - */ - declare export type SyncOptions = { - /** - * If force is true, each DAO will do DROP TABLE IF EXISTS ..., before it tries to create its own table - */ - force?: boolean, - - /** - * Match a regex against the database name before syncing, a safety check for cases where force: true is - * used in tests but not live code - */ - match?: RegExp, - - /** - * A function that logs sql queries, or false for no logging - */ - logging?: Function | boolean, - - /** - * The schema that the tables should be created in. This can be overriden for each table in sequelize.define - */ - schema?: string, - - /** - * Alters tables to fit models. Not recommended for production use. Deletes data in columns - * that were removed or had their type changed in the model. - */ - alter?: boolean, - - /** - * If hooks is true then beforeSync, afterSync, beforBulkSync, afterBulkSync hooks will be called - */ - hooks?: boolean, - - /** - * An optional parameter to specify the schema search_path (Postgres only) - */ - searchPath?: string - } - - declare export type SetOptions = {} - - - /** - * Connection Pool options - * @see Options - */ - declare export type PoolOptions = { - /** - * Maximum connections of the pool - */ - max?: number, - - /** - * Minimum connections of the pool - */ - min?: number, - - /** - * The maximum time, in milliseconds, that a connection can be idle before being released. - */ - idle?: number, - - /** - * The maximum time, in milliseconds, that pool will try to get connection before throwing error - */ - acquire?: number, - - /** - * A function that validates a connection. Called with client. The default function checks that client is an - * object, and that its state is not disconnected. - */ - validate?: (client?: any) => boolean, - evict?: number - } - - - /** - * Interface for replication Options in the sequelize constructor - * @see Options - */ - declare export type ReplicationOptions = { - read?: { - host?: string, - port?: string | number, - username?: string, - password?: string, - database?: string - }, - write?: { - host?: string, - port?: string | number, - username?: string, - password?: string, - database?: string - } - } - - - /** - * Interface for retry Options in the sequelize constructor and QueryOptions - * @see Options, QueryOptions - */ - declare export type RetryOptions = { - /** - * Only retry a query if the error matches one of these strings or Regexes. - */ - match?: Array, - - /** - * How many times a failing query is automatically retried. Set to 0 to disable retrying on SQL_BUSY error. - */ - max?: number - } - - - /** - * Operator symbols to be used when querying data - */ - declare export type Operators = { - eq: Symbol, - ne: Symbol, - gte: Symbol, - gt: Symbol, - lte: Symbol, - lt: Symbol, - not: Symbol, - is: Symbol, - in: Symbol, - notIn: Symbol, - like: Symbol, - notLike: Symbol, - iLike: Symbol, - notILike: Symbol, - regexp: Symbol, - notRegexp: Symbol, - iRegexp: Symbol, - notIRegexp: Symbol, - between: Symbol, - notBetween: Symbol, - overlap: Symbol, - contains: Symbol, - contained: Symbol, - adjacent: Symbol, - strictLeft: Symbol, - strictRight: Symbol, - noExtendRight: Symbol, - noExtendLeft: Symbol, - and: Symbol, - or: Symbol, - any: Symbol, - all: Symbol, - values: Symbol, - col: Symbol, - placeholder: Symbol, - join: Symbol, - raw: Symbol, - Aliases: { - '$eq': Symbol, - '$ne': Symbol, - '$gte': Symbol, - '$gt': Symbol, - '$lte': Symbol, - '$lt': Symbol, - '$not': Symbol, - '$in': Symbol, - '$notIn': Symbol, - '$is': Symbol, - '$like': Symbol, - '$notLike': Symbol, - '$iLike': Symbol, - '$notILike': Symbol, - '$regexp': Symbol, - '$notRegexp': Symbol, - '$iRegexp': Symbol, - '$notIRegexp': Symbol, - '$between': Symbol, - '$notBetween': Symbol, - '$overlap': Symbol, - '$contains': Symbol, - '$contained': Symbol, - '$adjacent': Symbol, - '$strictLeft': Symbol, - '$strictRight': Symbol, - '$noExtendRight': Symbol, - '$noExtendLeft': Symbol, - '$and': Symbol, - '$or': Symbol, - '$any': Symbol, - '$all': Symbol, - '$values': Symbol, - '$col': Symbol, - '$raw': Symbol, - }, - LegacyAliases: { - ne: Symbol, - not: Symbol, - in: Symbol, - notIn: Symbol, - gte: Symbol, - gt: Symbol, - lte: Symbol, - lt: Symbol, - like: Symbol, - ilike: Symbol, - '$ilike': Symbol, - nlike: Symbol, - '$notlike': Symbol, - notilike: Symbol, - '..': Symbol, - between: Symbol, - '!..': Symbol, - notbetween: Symbol, - nbetween: Symbol, - overlap: Symbol, - '&&': Symbol, - '@>': Symbol, - '<@': Symbol, - '$eq': Symbol, - '$ne': Symbol, - '$gte': Symbol, - '$gt': Symbol, - '$lte': Symbol, - '$lt': Symbol, - '$not': Symbol, - '$in': Symbol, - '$notIn': Symbol, - '$is': Symbol, - '$like': Symbol, - '$notLike': Symbol, - '$iLike': Symbol, - '$notILike': Symbol, - '$regexp': Symbol, - '$notRegexp': Symbol, - '$iRegexp': Symbol, - '$notIRegexp': Symbol, - '$between': Symbol, - '$notBetween': Symbol, - '$overlap': Symbol, - '$contains': Symbol, - '$contained': Symbol, - '$adjacent': Symbol, - '$strictLeft': Symbol, - '$strictRight': Symbol, - '$noExtendRight': Symbol, - '$noExtendLeft': Symbol, - '$and': Symbol, - '$or': Symbol, - '$any': Symbol, - '$all': Symbol, - '$values': Symbol, - '$col': Symbol, - '$raw': Symbol, - } - } - - declare export type OperatorsAliases = { - [key: string]: Symbol, - } - - - /** - * Options for the constructor of Sequelize main class - */ - declare export type Options = { - /** - * The dialect of the database you are connecting to. One of mysql, postgres, sqlite, mariadb and mssql. - * - Defaults to 'mysql' - */ - dialect?: string, - - /** - * If specified, load the dialect library from this path. For example, if you want to use pg.js instead of - * pg when connecting to a pg database, you should specify 'pg.js' here - */ - dialectModulePath?: string, - - /** - * An object of additional options, which are passed directly to the connection library - */ - dialectOptions?: Object, - - /** - * Only used by sqlite. - * - Defaults to ':memory:' - */ - storage?: string, - - /** - * The host of the relational database. - * - Defaults to 'localhost' - */ - host?: string, - - /** - * The port of the relational database. - */ - port?: number, - - /** - * The protocol of the relational database. - * - Defaults to 'tcp' - */ - protocol?: string, - - /** - * The username which is used to authenticate against the database. - */ - username?: string, - - /** - * The password which is used to authenticate against the database. - */ - password?: string, - - /** - * The name of the database - */ - database?: string, - - /** - * Default options for model definitions. See sequelize.define for options - */ - define?: DefineOptions, - - /** - * Default options for sequelize.query - */ - query?: QueryOptions, - - /** - * Default options for sequelize.set - */ - set?: SetOptions, - - /** - * Default options for sequelize.sync - */ - sync?: SyncOptions, - - /** - * The timezone used when converting a date from the database into a JavaScript date. The timezone is also - * used to SET TIMEZONE when connecting to the server, to ensure that the result of NOW, CURRENT_TIMESTAMP - and other time related functions have in the right timezone. For best cross platform performance use the - format - +/-HH:MM. Will also accept string versions of timezones used by moment.js (e.g. 'America/Los_Angeles'); - this is useful to capture daylight savings time changes. - - Defaults to '+00:00' - */ - timezone?: string, - - /** - * A function that gets executed everytime Sequelize would log something. - * - Defaults to console.log - */ - logging?: boolean | Function, - - /** - * A flag that defines if null values should be passed to SQL queries or not. - * - Defaults to false - */ - omitNull?: boolean, - - /** - * A flag that defines if native library shall be used or not. Currently only has an effect for postgres - * - Defaults to false - */ - native?: boolean, - - /** - * Use read / write replication. To enable replication, pass an object, with two properties, read and write. - * Write should be an object (a single server for handling writes), and read an array of object (several - servers to handle reads). Each read/write server can have the following properties: `host`, `port`, - `username`, `password`, `database` - - Defaults to false - */ - replication?: ReplicationOptions, - - /** - * Set of flags that control when a query is automatically retried. - */ - retry?: RetryOptions, - - /** - * Run built in type validators on insert and update, - * e.g. validate that arguments passed to integer fields are integer-like. - - Defaults to false - */ - typeValidation?: boolean, - - /** - * Connection pool options - */ - pool?: PoolOptions, - - /** - * Set to `false` to make table names and attributes case-insensitive on Postgres and skip double quoting of - * them. - - Defaults to true - */ - quoteIdentifiers?: boolean, - - /** - * Set the default transaction isolation level. See `Sequelize.Transaction.ISOLATION_LEVELS` for possible - * options. - - Defaults to 'REPEATABLE_READ' - */ - isolationLevel?: TransactionIsolationLevel, - - /** - * Set the default transaction type. See `Sequelize.Transaction.TYPES` for possible - * options. - - Defaults to 'DEFERRED' - */ - transactionType?: TransactionType, - - /** - * Print query execution time in milliseconds when logging SQL. - * - Defaults to false - */ - benchmark?: boolean, - - /** - * String based operator alias, default value is true which will enable all operators alias. - * Pass object to limit set of aliased operators or false to disable completely. - */ - operatorsAliases?: boolean | OperatorsAliases - } - - declare export type QueryOptionsTransactionRequired = { - transaction: Transaction, - } - - declare export type ModelsHashInterface = { - [name: string]: Class> - } - - - /** - * This is the main class, the entry point to sequelize. To use it, you just need to - * import sequelize: - - ```js - var Sequelize = require('sequelize'); - ``` - - In addition to sequelize, the connection library for the dialect you want to use - should also be installed in your project. You don't need to import it however, as - sequelize will take care of that. - */ - declare export default class Sequelize { - constructor(database: string, username?: ?string, password?: ?string, options?: Options): Sequelize; - constructor(database: string, options?: Options): Sequelize; - constructor(options: Options): Sequelize; - - /** - * A modified version of bluebird promises, that allows listening for sql events - */ - static Promise: typeof Promise, - Promise: typeof Promise, - - /** - * Available query types for use with `sequelize.query` - */ - static QueryTypes: QueryTypes, - QueryTypes: QueryTypes, - - /** - * Exposes the validator.js object, so you can extend it with custom validation functions. - * The validator is exposed both on the instance, and on the constructor. - */ - static Validator: Validator, - Validator: Validator, - - /** - * A Model represents a table in the database. Sometimes you might also see it referred to as model, or - * simply as factory. This class should not be instantiated directly, it is created using sequelize.define, - and already created models can be loaded using sequelize.import - */ - static Model: typeof Model, - Model: typeof Model, - - /** - * A reference to the sequelize transaction class. Use this to access isolationLevels when creating a - * transaction - */ - static Transaction: typeof Transaction, - Transaction: typeof Transaction, - - /** - * A reference to the deferrable collection. Use this to access the different deferrable options. - */ - static Deferrable: Deferrable, - Deferrable: Deferrable, - - /** - * A reference to the sequelize instance class. - */ - static Op: Operators, - Op: Operators, - - /** - * Creates a object representing a database function. This can be used in search queries, both in where and - * order parts, and as default values in column definitions. If you want to refer to columns in your - function, you should use `sequelize.col`, so that the columns are properly interpreted as columns and - not a strings. - - Convert a user's username to upper case - ```js - instance.updateAttributes({ - username: self.sequelize.fn('upper', self.sequelize.col('username')) - }) - ``` - * @param fn The function you want to call - * @param args All further arguments will be passed as arguments to the function - */ - static fn(fn: string, ...args: any[]): fn, - fn(fn: string, ...args: any[]): fn, - - /** - * Creates a object representing a column in the DB. This is often useful in conjunction with - * `sequelize.fn`, since raw string arguments to fn will be escaped. - * @param col The name of the column - */ - static col(col: string): col, - col(col: string): col, - - /** - * Creates a object representing a call to the cast function. - * @param val The value to cast - * @param type The type to cast it to - */ - static cast(val: any, type: string): cast, - cast(val: any, type: string): cast, - - /** - * Creates a object representing a literal, i.e. something that will not be escaped. - * @param val - */ - static literal(val: any): literal, - literal(val: any): literal, - static asIs(val: any): literal, - asIs(val: any): literal, - - /** - * An AND query - * @param args Each argument will be joined by AND - */ - static and(...args: $ReadOnlyArray): AndOperator, - and(...args: $ReadOnlyArray): AndOperator, - - /** - * An OR query - * @param args Each argument will be joined by OR - */ - static or(...args: $ReadOnlyArray): OrOperator, - or(...args: $ReadOnlyArray): OrOperator, - - /** - * Creates an object representing nested where conditions for postgres's json data-type. - * @param conditionsOrPath A hash containing strings/numbers or other nested hash, a string using dot - notation or a string using postgres json syntax. - * @param value An optional value to compare against. Produces a string of the form " = - ''". - */ - static json( - conditionsOrPath: string | Object, - value?: string | number | boolean): json, - json( - conditionsOrPath: string | Object, - value?: string | number | boolean): json, - - /** - * A way of specifying attr = condition. - * - The attr can either be an object taken from `Model.rawAttributes` (for example `Model.rawAttributes.id` - or - `Model.rawAttributes.name`). The attribute should be defined in your model definition. The attribute can - also be an object from one of the sequelize utility functions (`sequelize.fn`, `sequelize.col` etc.) - - For string attributes, use the regular `{ where: { attr: something }}` syntax. If you don't want your - string to be escaped, use `sequelize.literal`. - * @param attr The attribute, which can be either an attribute object from `Model.rawAttributes` or a - sequelize object, for example an instance of `sequelize.fn`. For simple string attributes, use the - POJO syntax - * @param comparator Comparator - * @param logic The condition. Can be both a simply type, or a further condition (`.or`, `.and`, `.literal` - etc.) - */ - static where(attr: Object, comparator: string, logic: string | Object): where, - where(attr: Object, comparator: string, logic: string | Object): where, - static where(attr: Object, logic: string | Object): where, - where(attr: Object, logic: string | Object): where, - static condition(attr: Object, comparator: string, logic: string | Object): where, - condition(attr: Object, comparator: string, logic: string | Object): where, - static condition(attr: Object, logic: string | Object): where, - condition(attr: Object, logic: string | Object): where, - - static Error: typeof BaseError, - static ValidationError: typeof ValidationError, - static ValidationErrorItem: typeof ValidationErrorItem, - static DatabaseError: typeof DatabaseError, - static TimeoutError: typeof TimeoutError, - static UniqueConstraintError: typeof UniqueConstraintError, - static ExclusionConstraintError: typeof ExclusionConstraintError, - static ForeignKeyConstraintError: typeof ForeignKeyConstraintError, - static ConnectionError: typeof ConnectionError, - static ConnectionRefusedError: typeof ConnectionRefusedError, - static AccessDeniedError: typeof AccessDeniedError, - static HostNotFoundError: typeof HostNotFoundError, - static HostNotReachableError: typeof HostNotReachableError, - static InvalidConnectionError: typeof InvalidConnectionError, - static ConnectionTimedOutError: typeof ConnectionTimedOutError, - static EmptyResultError: typeof EmptyResultError, - - Error: typeof BaseError, - ValidationError: typeof ValidationError, - ValidationErrorItem: typeof ValidationErrorItem, - DatabaseError: typeof DatabaseError, - TimeoutError: typeof TimeoutError, - UniqueConstraintError: typeof UniqueConstraintError, - ExclusionConstraintError: typeof ExclusionConstraintError, - ForeignKeyConstraintError: typeof ForeignKeyConstraintError, - ConnectionError: typeof ConnectionError, - ConnectionRefusedError: typeof ConnectionRefusedError, - AccessDeniedError: typeof AccessDeniedError, - HostNotFoundError: typeof HostNotFoundError, - HostNotReachableError: typeof HostNotReachableError, - InvalidConnectionError: typeof InvalidConnectionError, - ConnectionTimedOutError: typeof ConnectionTimedOutError, - EmptyResultError: typeof EmptyResultError, - - static ABSTRACT: DataTypeAbstract, - static STRING: DataTypeString, - static CHAR: DataTypeChar, - static TEXT: DataTypeText, - static NUMBER: DataTypeNumber, - static INTEGER: DataTypeInteger, - static BIGINT: DataTypeBigInt, - static FLOAT: DataTypeFloat, - static TIME: DataTypeTime, - static DATE: DataTypeDate, - static DATEONLY: DataTypeDateOnly, - static BOOLEAN: DataTypeBoolean, - static NOW: DataTypeNow, - static BLOB: DataTypeBlob, - static DECIMAL: DataTypeDecimal, - static NUMERIC: DataTypeDecimal, - static UUID: DataTypeUUID, - static UUIDV1: DataTypeUUIDv1, - static UUIDV4: DataTypeUUIDv4, - static HSTORE: DataTypeHStore, - static JSON: DataTypeJSONType, - static JSONB: DataTypeJSONB, - static VIRTUAL: DataTypeVirtual, - static ARRAY: DataTypeArray, - static NONE: DataTypeVirtual, - static ENUM: DataTypeEnum, - static RANGE: DataTypeRange, - static REAL: DataTypeReal, - static DOUBLE: DataTypeDouble, - static GEOMETRY: DataTypeGeometry, - - /** - * Add a hook to the model - * @param hookType - * @param name Provide a name for the hook function. It can be used to remove the hook later or to order - hooks based on some sort of priority system in the future. - * @param fn The hook function - * @alias hook - */ - static addHook(hookType: string, name: string, fn: Function): this, - static addHook(hookType: string, fn: Function): this, - static hook(hookType: string, name: string, fn: Function): this, - static hook(hookType: string, fn: Function): this, - - /** - * Remove hook from the model - * @param hookType - * @param name - */ - static removeHook(hookType: string, name: string): this, - - /** - * Check whether the model has any hooks of this type - * @param hookType - * @alias hasHooks - */ - static hasHook(hookType: string): boolean, - static hasHooks(hookType: string): boolean, - - /** - * A hook that is run before validation - * @param name - * @param fn A callback function that is called with instance, options - */ - static beforeValidate( - name: string, - fn: AsyncFn2, Object>): void, - static beforeValidate(fn: AsyncFn2, Object>): void, - - /** - * A hook that is run after validation - * @param name - * @param fn A callback function that is called with instance, options - */ - static afterValidate( - name: string, - fn: AsyncFn2, Object>): void, - static afterValidate(fn: AsyncFn2, Object>): void, - - /** - * A hook that is run after validation - * @param name - * @param fn A callback function that is called with instance, options - */ - static validationFailed( - name: string, - fn: AsyncFn3, Object, ValidationError>): void, - static validationFailed(fn: AsyncFn3, Object, ValidationError>): void, - - /** - * A hook that is run before creating a single instance - * @param name - * @param fn A callback function that is called with attributes, options - */ - static beforeCreate( - name: string, - fn: AsyncFn2, Object>): void, - static beforeCreate(fn: AsyncFn2, Object>): void, - - /** - * A hook that is run after creating a single instance - * @param name - * @param fn A callback function that is called with attributes, options - */ - static afterCreate( - name: string, - fn: AsyncFn2, Object>): void, - static afterCreate(fn: AsyncFn2, Object>): void, - - /** - * A hook that is run before destroying a single instance - * @param name - * @param fn A callback function that is called with instance, options - * @alias beforeDelete - */ - static beforeDestroy( - name: string, - fn: AsyncFn2, Object>): void, - static beforeDestroy(fn: AsyncFn2, Object>): void, - static beforeDelete( - name: string, - fn: AsyncFn2, Object>): void, - static beforeDelete(fn: AsyncFn2, Object>): void, - - /** - * A hook that is run after destroying a single instance - * @param name - * @param fn A callback function that is called with instance, options - * @alias afterDelete - */ - static afterDestroy( - name: string, - fn: AsyncFn2, Object>): void, - static afterDestroy(fn: AsyncFn2, Object>): void, - static afterDelete( - name: string, - fn: AsyncFn2, Object>): void, - static afterDelete(fn: AsyncFn2, Object>): void, - - /** - * A hook that is run before updating a single instance - * @param name - * @param fn A callback function that is called with instance, options - */ - static beforeUpdate( - name: string, - fn: AsyncFn2, Object>): void, - static beforeUpdate(fn: AsyncFn2, Object>): void, - - /** - * A hook that is run after updating a single instance - * @param name - * @param fn A callback function that is called with instance, options - */ - static afterUpdate( - name: string, - fn: AsyncFn2, Object>): void, - static afterUpdate(fn: AsyncFn2, Object>): void, - - /** - * A hook that is run before creating instances in bulk - * @param name - * @param fn A callback function that is called with instances, options - */ - static beforeBulkCreate( - name: string, - fn: AsyncFn2[], Object>): void, - static beforeBulkCreate(fn: AsyncFn2[], Object>): void, - - /** - * A hook that is run after creating instances in bulk - * @param name - * @param fn A callback function that is called with instances, options - * @name afterBulkCreate - */ - static afterBulkCreate( - name: string, - fn: AsyncFn2[], Object>): void, - static afterBulkCreate(fn: AsyncFn2[], Object>): void, - - /** - * A hook that is run before destroying instances in bulk - * @param name - * @param fn A callback function that is called with options - * @alias beforeBulkDelete - */ - static beforeBulkDestroy(name: string, fn: AsyncFn1): void, - static beforeBulkDestroy(fn: AsyncFn1): void, - static beforeBulkDelete(name: string, fn: AsyncFn1): void, - static beforeBulkDelete(fn: AsyncFn1): void, - - /** - * A hook that is run after destroying instances in bulk - * @param name - * @param fn A callback function that is called with options - * @alias afterBulkDelete - */ - static afterBulkDestroy(name: string, fn: AsyncFn1): void, - static afterBulkDestroy(fn: AsyncFn1): void, - static afterBulkDelete(name: string, fn: AsyncFn1): void, - static afterBulkDelete(fn: AsyncFn1): void, - - /** - * A hook that is run after updating instances in bulk - * @param name - * @param fn A callback function that is called with options - */ - static beforeBulkUpdate(name: string, fn: AsyncFn1): void, - static beforeBulkUpdate(fn: AsyncFn1): void, - - /** - * A hook that is run after updating instances in bulk - * @param name - * @param fn A callback function that is called with options - */ - static afterBulkUpdate(name: string, fn: AsyncFn1): void, - static afterBulkUpdate(fn: AsyncFn1): void, - - /** - * A hook that is run before a find (select) query - * @param name - * @param fn A callback function that is called with options - */ - static beforeFind(name: string, fn: AsyncFn1): void, - static beforeFind(fn: AsyncFn1): void, - - /** - * A hook that is run before a find (select) query, after any { include: {all: ...} } options are expanded - * @param name - * @param fn A callback function that is called with options - */ - static beforeFindAfterExpandIncludeAll(name: string, fn: AsyncFn1): void, - static beforeFindAfterExpandIncludeAll(fn: AsyncFn1): void, - - /** - * A hook that is run before a find (select) query, after all option parsing is complete - * @param name - * @param fn A callback function that is called with options - */ - static beforeFindAfterOptions(name: string, fn: AsyncFn1): void, - static beforeFindAfterOptions(fn: AsyncFn1): void, - - /** - * A hook that is run after a find (select) query - * @param name - * @param fn A callback function that is called with instance(s), options - */ - static afterFind( - name: string, - AsyncFn2 | Model[], Object>): void, - static afterFind( - AsyncFn2 | Model[], Object>): void, - - /** - * A hook that is run before a define call - * @param name - * @param fn A callback function that is called with attributes, options - */ - static beforeDefine( - name: string, - fn: AsyncFn2): void, - static beforeDefine(fn: AsyncFn2): void, - - /** - * A hook that is run after a define call - * @param name - * @param fn A callback function that is called with factory - */ - static afterDefine(name: string, fn: AsyncFn1, any>>): void, - static afterDefine(fn: AsyncFn1, any>>): void, - - /** - * A hook that is run before Sequelize() call - * @param name - * @param fn A callback function that is called with config, options - */ - static beforeInit(name: string, fn: AsyncFn2): void, - static beforeInit(fn: AsyncFn2): void, - - /** - * A hook that is run after Sequelize() call - * @param name - * @param fn A callback function that is called with sequelize - */ - static afterInit(name: string, fn: AsyncFn1): void, - static afterInit(fn: AsyncFn1): void, - - /** - * A hook that is run before Model.sync call - * @param name - * @param fn A callback function that is called with options passed to Model.sync - */ - static beforeSync(name: string, fn: AsyncFn1): void, - static beforeSync(fn: AsyncFn1): void, - - /** - * A hook that is run after Model.sync call - * @param name - * @param fn A callback function that is called with options passed to Model.sync - */ - static afterSync(name: string, fn: AsyncFn1): void, - static afterSync(fn: AsyncFn1): void, - - /** - * A hook that is run before sequelize.sync call - * @param name - * @param fn A callback function that is called with options passed to sequelize.sync - */ - static beforeBulkSync(name: string, fn: AsyncFn1): void, - static beforeBulkSync(fn: AsyncFn1): void, - - /** - * A hook that is run after sequelize.sync call - * @param name - * @param fn A callback function that is called with options passed to sequelize.sync - */ - static afterBulkSync(name: string, fn: AsyncFn1): void, - static afterBulkSync(fn: AsyncFn1): void, - - /** - * Add a hook to the model - * @param hookType - * @param name Provide a name for the hook function. It can be used to remove the hook later or to order - hooks based on some sort of priority system in the future. - * @param fn The hook function - * @alias hook - */ - addHook(hookType: string, name: string, fn: Function): this, - addHook(hookType: string, fn: Function): this, - hook(hookType: string, name: string, fn: Function): this, - hook(hookType: string, fn: Function): this, - - /** - * Remove hook from the model - * @param hookType - * @param name - */ - removeHook(hookType: string, name: string): this, - - /** - * Check whether the model has any hooks of this type - * @param hookType - * @alias hasHooks - */ - hasHook(hookType: string): boolean, - hasHooks(hookType: string): boolean, - - /** - * A hook that is run before validation - * @param name - * @param fn A callback function that is called with instance, options - */ - beforeValidate( - name: string, - fn: AsyncFn2, Object>): void, - beforeValidate(fn: AsyncFn2, Object>): void, - - /** - * A hook that is run after validation - * @param name - * @param fn A callback function that is called with instance, options - */ - afterValidate( - name: string, - fn: AsyncFn2, Object>): void, - afterValidate(fn: AsyncFn2, Object>): void, - - /** - * A hook that is run after validation - * @param name - * @param fn A callback function that is called with instance, options - */ - validationFailed( - name: string, - fn: AsyncFn3, Object, ValidationError>): void, - validationFailed(fn: AsyncFn3, Object, ValidationError>): void, - - /** - * A hook that is run before creating a single instance - * @param name - * @param fn A callback function that is called with attributes, options - */ - beforeCreate( - name: string, - fn: AsyncFn2, Object>): void, - beforeCreate(fn: AsyncFn2, Object>): void, - - /** - * A hook that is run after creating a single instance - * @param name - * @param fn A callback function that is called with attributes, options - */ - afterCreate( - name: string, - fn: AsyncFn2, Object>): void, - afterCreate(fn: AsyncFn2, Object>): void, - - /** - * A hook that is run before destroying a single instance - * @param name - * @param fn A callback function that is called with instance, options - * @alias beforeDelete - */ - beforeDestroy( - name: string, - fn: AsyncFn2, Object>): void, - beforeDestroy(fn: AsyncFn2, Object>): void, - beforeDelete( - name: string, - fn: AsyncFn2, Object>): void, - beforeDelete(fn: AsyncFn2, Object>): void, - - /** - * A hook that is run after destroying a single instance - * @param name - * @param fn A callback function that is called with instance, options - * @alias afterDelete - */ - afterDestroy( - name: string, - fn: AsyncFn2, Object>): void, - afterDestroy(fn: AsyncFn2, Object>): void, - afterDelete( - name: string, - fn: AsyncFn2, Object>): void, - afterDelete(fn: AsyncFn2, Object>): void, - - /** - * A hook that is run before updating a single instance - * @param name - * @param fn A callback function that is called with instance, options - */ - beforeUpdate( - name: string, - fn: AsyncFn2, Object>): void, - beforeUpdate(fn: AsyncFn2, Object>): void, - - /** - * A hook that is run after updating a single instance - * @param name - * @param fn A callback function that is called with instance, options - */ - afterUpdate( - name: string, - fn: AsyncFn2, Object>): void, - afterUpdate(fn: AsyncFn2, Object>): void, - - /** - * A hook that is run before creating instances in bulk - * @param name - * @param fn A callback function that is called with instances, options - */ - beforeBulkCreate( - name: string, - fn: AsyncFn2[], Object>): void, - beforeBulkCreate(fn: AsyncFn2[], Object>): void, - - /** - * A hook that is run after creating instances in bulk - * @param name - * @param fn A callback function that is called with instances, options - * @name afterBulkCreate - */ - afterBulkCreate( - name: string, - fn: AsyncFn2[], Object>): void, - afterBulkCreate(fn: AsyncFn2[], Object>): void, - - /** - * A hook that is run before destroying instances in bulk - * @param name - * @param fn A callback function that is called with options - * @alias beforeBulkDelete - */ - beforeBulkDestroy(name: string, fn: AsyncFn1): void, - beforeBulkDestroy(fn: AsyncFn1): void, - beforeBulkDelete(name: string, fn: AsyncFn1): void, - beforeBulkDelete(fn: AsyncFn1): void, - - /** - * A hook that is run after destroying instances in bulk - * @param name - * @param fn A callback function that is called with options - * @alias afterBulkDelete - */ - afterBulkDestroy(name: string, fn: AsyncFn1): void, - afterBulkDestroy(fn: AsyncFn1): void, - afterBulkDelete(name: string, fn: AsyncFn1): void, - afterBulkDelete(fn: AsyncFn1): void, - - /** - * A hook that is run after updating instances in bulk - * @param name - * @param fn A callback function that is called with options - */ - beforeBulkUpdate(name: string, fn: AsyncFn1): void, - beforeBulkUpdate(fn: AsyncFn1): void, - - /** - * A hook that is run after updating instances in bulk - * @param name - * @param fn A callback function that is called with options - */ - afterBulkUpdate(name: string, fn: AsyncFn1): void, - afterBulkUpdate(fn: AsyncFn1): void, - - /** - * A hook that is run before a find (select) query - * @param name - * @param fn A callback function that is called with options - */ - beforeFind(name: string, fn: AsyncFn1): void, - beforeFind(fn: AsyncFn1): void, - - /** - * A hook that is run before a find (select) query, after any { include: {all: ...} } options are expanded - * @param name - * @param fn A callback function that is called with options - */ - beforeFindAfterExpandIncludeAll(name: string, fn: AsyncFn1): void, - beforeFindAfterExpandIncludeAll(fn: AsyncFn1): void, - - /** - * A hook that is run before a find (select) query, after all option parsing is complete - * @param name - * @param fn A callback function that is called with options - */ - beforeFindAfterOptions(name: string, fn: AsyncFn1): void, - beforeFindAfterOptions(fn: AsyncFn1): void, - - /** - * A hook that is run after a find (select) query - * @param name - * @param fn A callback function that is called with instance(s), options - */ - afterFind( - name: string, - AsyncFn2 | Model[], Object>): void, - afterFind( - AsyncFn2 | Model[], Object>): void, - - /** - * A hook that is run before a define call - * @param name - * @param fn A callback function that is called with attributes, options - */ - beforeDefine( - name: string, - fn: AsyncFn2): void, - beforeDefine(fn: AsyncFn2): void, - - /** - * A hook that is run after a define call - * @param name - * @param fn A callback function that is called with factory - */ - afterDefine(name: string, fn: AsyncFn1, any>>): void, - afterDefine(fn: AsyncFn1, any>>): void, - - /** - * A hook that is run before Sequelize() call - * @param name - * @param fn A callback function that is called with config, options - */ - beforeInit(name: string, fn: AsyncFn2): void, - beforeInit(fn: AsyncFn2): void, - - /** - * A hook that is run after Sequelize() call - * @param name - * @param fn A callback function that is called with sequelize - */ - afterInit(name: string, fn: AsyncFn1): void, - afterInit(fn: AsyncFn1): void, - - /** - * A hook that is run before Model.sync call - * @param name - * @param fn A callback function that is called with options passed to Model.sync - */ - beforeSync(name: string, fn: AsyncFn1): void, - beforeSync(fn: AsyncFn1): void, - - /** - * A hook that is run after Model.sync call - * @param name - * @param fn A callback function that is called with options passed to Model.sync - */ - afterSync(name: string, fn: AsyncFn1): void, - afterSync(fn: AsyncFn1): void, - - /** - * A hook that is run before sequelize.sync call - * @param name - * @param fn A callback function that is called with options passed to sequelize.sync - */ - beforeBulkSync(name: string, fn: AsyncFn1): void, - beforeBulkSync(fn: AsyncFn1): void, - - /** - * A hook that is run after sequelize.sync call - * @param name - * @param fn A callback function that is called with options passed to sequelize.sync - */ - afterBulkSync(name: string, fn: AsyncFn1): void, - afterBulkSync(fn: AsyncFn1): void, - - /** - * Defined models. - */ - models: ModelsHashInterface, - - /** - * Defined options. - */ - options: Options, - - /** - * Returns the specified dialect. - */ - getDialect(): string, - - /** - * Returns an instance of QueryInterface. - */ - getQueryInterface(): QueryInterface, - - /** - * Define a new model, representing a table in the DB. - * - The table columns are define by the hash that is given as the second argument. Each attribute of the - hash - represents a column. A short table definition might look like this: - - ```js - sequelize.define('modelName', { - columnA: { - type: Sequelize.BOOLEAN, - validate: { - is: ["[a-z]",'i'], // will only allow letters - max: 23, // only allow values <= 23 - isIn: { - args: [['en', 'zh']], - msg: "Must be English or Chinese" - } - }, - field: 'column_a' - // Other attributes here - }, - columnB: Sequelize.STRING, - columnC: 'MY VERY OWN COLUMN TYPE' - }) - - sequelize.models.modelName // The model will now be available in models under the name given to define - ``` - - As shown above, column definitions can be either strings, a reference to one of the datatypes that are - predefined on the Sequelize constructor, or an object that allows you to specify both the type of the - column, and other attributes such as default values, foreign key constraints and custom setters and - getters. - - For a list of possible data types, see - http://docs.sequelizejs.com/en/latest/docs/models-definition/#data-types - - For more about getters and setters, see - http://docs.sequelizejs.com/en/latest/docs/models-definition/#getters-setters - - For more about instance and class methods, see - http://docs.sequelizejs.com/en/latest/docs/models-definition/#expansion-of-models - - For more about validation, see - http://docs.sequelizejs.com/en/latest/docs/models-definition/#validations - * @param modelName The name of the model. The model will be stored in `sequelize.models` under this name - * @param attributes An object, where each attribute is a column of the table. Each column can be either a - DataType, a string or a type-description object, with the properties described below: - * @param options These options are merged with the default define options provided to the Sequelize - constructor - */ - define>( - modelName: string, - attributes: DefineAttributes, - options?: DefineOptions): Class, - - /** - * Fetch a Model which is already defined - * @param modelName The name of a model defined with Sequelize.define - */ - model>>(modelName: string): ModelClass, - - /** - * Checks whether a model with the given name is defined - * @param modelName The name of a model defined with Sequelize.define - */ - isDefined(modelName: string): boolean, - - /** - * Imports a model defined in another file - * - Imported models are cached, so multiple calls to import with the same path will not load the file - multiple times - - See https://github.com/sequelize/sequelize/blob/master/examples/using-multiple-model-files/Task.js for a - short example of how to define your models in separate files so that they can be imported by - sequelize.import - * @param path The path to the file that holds the model you want to import. If the part is relative, it - will be resolved relatively to the calling file - * @param defineFunction An optional function that provides model definitions. Useful if you do not - want to use the module root as the define function - */ - import>>( - path: string, - defineFunction?: ( - sequelize: Sequelize, - dataTypes: DataTypes) => ModelClass): ModelClass, - - /** - * Execute a query on the DB, with the posibility to bypass all the sequelize goodness. - * - By default, the function will return two arguments: an array of results, and a metadata object, - containing number of affected rows etc. Use `.spread` to access the results. - - If you are running a type of query where you don't need the metadata, for example a `SELECT` query, you - can pass in a query type to make sequelize format the results: - - ```js - sequelize.query('SELECT...').spread(function (results, metadata) { - // Raw query - use spread - }); - - sequelize.query('SELECT...', { type: sequelize.QueryTypes.SELECT }).then(function (results) { - // SELECT query - use then - }) - ``` - * @param sql - * @param options Query options - */ - query( - sql: string | { - query: string, - values: any[] - }, - options?: QueryOptions): Promise, - - /** - * Execute a query which would set an environment or user variable. The variables are set per connection, - * so this function needs a transaction. - - Only works for MySQL. - * @param variables Object with multiple variables. - * @param options Query options. - */ - set( - variables: Object, - options: QueryOptionsTransactionRequired): Promise, - - /** - * Escape value. - * @param value Value that needs to be escaped - */ - escape(value: string): string, - - /** - * Create a new database schema. - * - Note,that this is a schema in the - [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html), - not a database table. In mysql and sqlite, this command will do nothing. - * @param schema Name of the schema - * @param options Options supplied - * @param options .logging A function that logs sql queries, or false for no logging - */ - createSchema(schema: string, options: { - logging?: boolean | Function - }): Promise, - - /** - * Show all defined schemas - * - Note,that this is a schema in the - [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html), - not a database table. In mysql and sqlite, this will show all tables. - * @param options Options supplied - * @param options .logging A function that logs sql queries, or false for no logging - */ - showAllSchemas(options: { - logging?: boolean | Function - }): Promise, - - /** - * Drop a single schema - * - Note,that this is a schema in the - [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html), - not a database table. In mysql and sqlite, this drop a table matching the schema name - * @param schema Name of the schema - * @param options Options supplied - * @param options .logging A function that logs sql queries, or false for no logging - */ - dropSchema(schema: string, options: { - logging?: boolean | Function - }): Promise, - - /** - * Drop all schemas - * - Note,that this is a schema in the - [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html), - not a database table. In mysql and sqlite, this is the equivalent of drop all tables. - * @param options Options supplied - * @param options .logging A function that logs sql queries, or false for no logging - */ - dropAllSchemas(options: { - logging?: boolean | Function - }): Promise, - - /** - * Sync all defined models to the DB. - * @param options Sync Options - */ - sync(options?: SyncOptions): Promise, - - /** - * Truncate all tables defined through the sequelize models. This is done - * by calling Model.truncate() on each model. - * @param The options passed to Model.destroy in addition to truncate - * @param .transaction] - * @param .logging] A function that logs sql queries, or false for no logging - */ - truncate(options?: DestroyOptions): Promise, - - /** - * Drop all tables defined through this sequelize instance. This is done by calling Model.drop on each model - * @see {Model#drop} for options - * @param options The options passed to each call to Model.drop - */ - drop(options?: DropOptions): Promise, - - /** - * Test the connection by trying to authenticate - * @param options Query Options for authentication - */ - authenticate(options?: QueryOptions): Promise, - validate(options?: QueryOptions): Promise, - - /** - * Start a transaction. When using transactions, you should pass the transaction in the options argument - * in order for the query to happen under that transaction - - ```js - sequelize.transaction().then(function (t) { - return User.find(..., { transaction: t}).then(function (user) { - return user.updateAttributes(..., { transaction: t}); - }) - .then(t.commit.bind(t)) - .catch(t.rollback.bind(t)); - }) - ``` - - A syntax for automatically committing or rolling back based on the promise chain resolution is also - supported: - - ```js - sequelize.transaction(function (t) { // Note that we use a callback rather than a promise.then() - return User.find(..., { transaction: t}).then(function (user) { - return user.updateAttributes(..., { transaction: t}); - }); - }).then(function () { - // Commited - }).catch(function (err) { - // Rolled back - console.error(err); - }); - ``` - - If you have [CLS](https://github.com/othiym23/node-continuation-local-storage) enabled, the transaction - will automatically be passed to any query that runs witin the callback. To enable CLS, add it do your - project, create a namespace and set it on the sequelize constructor: - - ```js - var cls = require('continuation-local-storage'), - ns = cls.createNamespace('....'); - var Sequelize = require('sequelize'); - Sequelize.cls = ns; - ``` - Note, that CLS is enabled for all sequelize instances, and all instances will share the same namespace - * @param options Transaction Options - * @param autoCallback Callback for the transaction - */ - transaction>(autoCallback: Fn): Promise, - transaction>( - options: TransactionOptions, - autoCallback: Fn): Promise, - transaction(options?: TransactionOptions): Promise, - - /** - * Close all connections used by this sequelize instance, and free all references so the instance can be - * garbage collected. - - Normally this is done on process exit, so you only need to call this method if you are creating multiple - instances, and want to garbage collect some of them. - */ - close(): Promise, - - /** - * Returns the database version - */ - databaseVersion(): Promise, - } - - - - /** - * Validator Interface - */ - declare export type Validator = { - notEmpty(str: string): boolean, - len(str: string, min: number, max: number): boolean, - isUrl(str: string): boolean, - isIPv6(str: string): boolean, - isIPv4(str: string): boolean, - notIn(str: string, values: string[]): boolean, - regex(str: string, pattern: string, modifiers: string): boolean, - notRegex(str: string, pattern: string, modifiers: string): boolean, - isDecimal(str: string): boolean, - min(str: string, val: number): boolean, - max(str: string, val: number): boolean, - not(str: string, pattern: string, modifiers: string): boolean, - contains(str: string, element: string[]): boolean, - notContains(str: string, element: string[]): boolean, - is(str: string, pattern: string, modifiers: string): boolean - } - - - /** - * The transaction object is used to identify a running transaction. It is created by calling - * `Sequelize.transaction()`. - - To run a query under a transaction, you should pass the transaction in the options object. - */ - declare export class Transaction { - /** - * Commit the transaction - */ - commit(): Promise, - - /** - * Rollback (abort) the transaction - */ - rollback(): Promise, - - /** - * Isolations levels can be set per-transaction by passing `options.isolationLevel` to - * `sequelize.transaction`. Default to `REPEATABLE_READ` but you can override the default isolation level - by passing - `options.isolationLevel` in `new Sequelize`. - - The possible isolations levels to use when starting a transaction: - - ```js - { - READ_UNCOMMITTED: "READ_UNCOMMITTED", - READ_COMMITTED: "READ_COMMITTED", - REPEATABLE_READ: "REPEATABLE_READ", - SERIALIZABLE: "SERIALIZABLE" - } - ``` - - Pass in the desired level as the first argument: - - ```js - return sequelize.transaction({ - isolationLevel: Sequelize.Transaction.SERIALIZABLE - }, function (t) { - - // your transactions - - }).then(function(result) { - // transaction has been committed. Do something after the commit if required. - }).catch(function(err) { - // do something with the err. - }); - ``` - * @see ISOLATION_LEVELS - */ - static ISOLATION_LEVELS: TransactionIsolationLevels, - ISOLATION_LEVELS: TransactionIsolationLevels, - - /** - * Transaction type can be set per-transaction by passing `options.type` to - * `sequelize.transaction`. Default to `DEFERRED` but you can override the default isolation level - by passing `options.transactionType` in `new Sequelize`. - - The transaction types to use when starting a transaction: - - ```js - { - DEFERRED: "DEFERRED", - IMMEDIATE: "IMMEDIATE", - EXCLUSIVE: "EXCLUSIVE" - } - ``` - - Pass in the transaction type the first argument: - - ```js - return sequelize.transaction({ - type: Sequelize.Transaction.EXCLUSIVE - }, function (t) { - - // your transactions - - }).then(function(result) { - // transaction has been committed. Do something after the commit if required. - }).catch(function(err) { - // do something with the err. - }); - ``` - * @see Sequelize.Transaction.TYPES - */ - static TYPES: TransactionTypes, - TYPES: TransactionTypes, - - /** - * Possible options for row locking. Used in conjuction with `find` calls: - * - ```js - t1 // is a transaction - t1.LOCK.UPDATE, - t1.LOCK.SHARE, - t1.LOCK.KEY_SHARE, // Postgres 9.3+ only - t1.LOCK.NO_KEY_UPDATE // Postgres 9.3+ only - ``` - - Usage: - ```js - t1 // is a transaction - Model.findAll({ - where: ..., - transaction: t1, - lock: t1.LOCK... - }); - ``` - - Postgres also supports specific locks while eager loading by using OF: - ```js - UserModel.findAll({ - where: ..., - include: [TaskModel, ...], - transaction: t1, - lock: { - level: t1.LOCK..., - of: UserModel - } - }); - ``` - UserModel will be locked but TaskModel won't! - */ - static LOCK: TransactionLock, - LOCK: TransactionLock, - } - - declare export type TransactionIsolationLevelReadUncommitted = 'READ_UNCOMMITTED'; - - declare export type TransactionIsolationLevelReadCommitted = 'READ_COMMITTED'; - - declare export type TransactionIsolationLevelRepeatableRead = 'REPEATABLE_READ'; - - declare export type TransactionIsolationLevelSerializable = 'SERIALIZABLE'; - - declare export type TransactionIsolationLevel = TransactionIsolationLevelReadUncommitted | TransactionIsolationLevelReadCommitted | TransactionIsolationLevelRepeatableRead | TransactionIsolationLevelSerializable; - - - /** - * Isolations levels can be set per-transaction by passing `options.isolationLevel` to `sequelize.transaction`. - * Default to `REPEATABLE_READ` but you can override the default isolation level by passing - `options.isolationLevel` in `new Sequelize`. - */ - declare export type TransactionIsolationLevels = { - READ_UNCOMMITTED: TransactionIsolationLevelReadUncommitted, - READ_COMMITTED: TransactionIsolationLevelReadCommitted, - REPEATABLE_READ: TransactionIsolationLevelRepeatableRead, - SERIALIZABLE: TransactionIsolationLevelSerializable - } - - declare export type TransactionTypeDeferred = 'DEFERRED'; - - declare export type TransactionTypeImmediate = 'IMMEDIATE'; - - declare export type TransactionTypeExclusive = 'EXCLUSIVE'; - - declare export type TransactionType = TransactionTypeDeferred | TransactionTypeImmediate | TransactionTypeExclusive; - - - /** - * Transaction type can be set per-transaction by passing `options.type` to `sequelize.transaction`. - * Default to `DEFERRED` but you can override the default isolation level by passing - `options.transactionType` in `new Sequelize`. - */ - declare export type TransactionTypes = { - DEFERRED: TransactionTypeDeferred, - IMMEDIATE: TransactionTypeImmediate, - EXCLUSIVE: TransactionTypeExclusive - } - - declare export type TransactionLockLevelUpdate = 'UPDATE'; - - declare export type TransactionLockLevelShare = 'SHARE'; - - declare export type TransactionLockLevelKeyShare = 'KEY_SHARE'; - - declare export type TransactionLockLevelNoKeyUpdate = 'NO_KEY_UPDATE'; - - declare export type TransactionLockLevel = - TransactionLockLevelUpdate | - TransactionLockLevelShare | - TransactionLockLevelKeyShare | - TransactionLockLevelNoKeyUpdate; - - /** - * Possible options for row locking. Used in conjuction with `find` calls: - */ - declare export type TransactionLock = { - UPDATE: TransactionLockLevelUpdate, - SHARE: TransactionLockLevelShare, - KEY_SHARE: TransactionLockLevelKeyShare, - NO_KEY_UPDATE: TransactionLockLevelNoKeyUpdate - } - - - /** - * Options provided when the transaction is created - * @see sequelize.transaction() - */ - declare export type TransactionOptions = { - autocommit?: boolean, - - /** - * See `Sequelize.Transaction.ISOLATION_LEVELS` for possible options - */ - isolationLevel?: TransactionIsolationLevel, - - /** - * See `Sequelize.Transaction.TYPES` for possible options - */ - type?: TransactionType, - - /** - * A function that gets executed while running the query to log the sql. - */ - logging?: Function - } - - declare type TransactionAutoCallback = (t:Transaction) => Promise | T - - declare export interface fn { - fn: string, - args: any[] - } - - declare export interface col { - col: string - } - - declare export interface cast { - val: any, - type: string - } - - declare export interface literal { - val: any - } - - declare export interface json { - conditions?: Object, - path?: string, - value?: string | number | boolean - } - - declare export interface where { - attribute: Object, - comparator?: string, - logic: string | Object - } -} diff --git a/package.json b/package.json index 1cf7ae7b..c7ac1588 100644 --- a/package.json +++ b/package.json @@ -144,9 +144,9 @@ "redis-lock": "^0.1.0", "rich-markdown-editor": "^9.6.1", "safestart": "1.1.0", - "sequelize": "4.28.6", - "sequelize-cli": "^5.4.0", - "sequelize-encrypted": "0.1.0", + "sequelize": "^5.8.12", + "sequelize-cli": "^5.5.0", + "sequelize-encrypted": "^0.1.0", "slug": "^1.0.0", "socket.io": "^2.2.0", "socketio-auth": "^0.1.1", diff --git a/server/api/__snapshots__/users.test.js.snap b/server/api/__snapshots__/users.test.js.snap index 30c929ce..22e696a3 100644 --- a/server/api/__snapshots__/users.test.js.snap +++ b/server/api/__snapshots__/users.test.js.snap @@ -4,7 +4,7 @@ exports[`#users.activate should activate a suspended user 1`] = ` Object { "data": Object { "avatarUrl": "http://example.com/avatar.png", - "createdAt": "2018-01-01T00:00:00.000Z", + "createdAt": "2018-01-02T00:00:00.000Z", "email": "user1@example.com", "id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61", "isAdmin": false, @@ -38,7 +38,7 @@ exports[`#users.demote should demote an admin 1`] = ` Object { "data": Object { "avatarUrl": "http://example.com/avatar.png", - "createdAt": "2018-01-01T00:00:00.000Z", + "createdAt": "2018-01-02T00:00:00.000Z", "email": "user1@example.com", "id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61", "isAdmin": false, @@ -71,6 +71,14 @@ Object { exports[`#users.list should require admin for detailed info 1`] = ` Object { "data": Array [ + Object { + "avatarUrl": "http://example.com/avatar.png", + "createdAt": "2018-01-02T00:00:00.000Z", + "id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61", + "isAdmin": false, + "isSuspended": false, + "name": "User 1", + }, Object { "avatarUrl": "http://example.com/avatar.png", "createdAt": "2018-01-01T00:00:00.000Z", @@ -79,14 +87,6 @@ Object { "isSuspended": false, "name": "Admin User", }, - Object { - "avatarUrl": "http://example.com/avatar.png", - "createdAt": "2018-01-01T00:00:00.000Z", - "id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61", - "isAdmin": false, - "isSuspended": false, - "name": "User 1", - }, ], "ok": true, "pagination": Object { @@ -103,7 +103,7 @@ Object { "data": Array [ Object { "avatarUrl": "http://example.com/avatar.png", - "createdAt": "2018-01-01T00:00:00.000Z", + "createdAt": "2018-01-02T00:00:00.000Z", "email": "user1@example.com", "id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61", "isAdmin": false, @@ -134,7 +134,7 @@ exports[`#users.promote should promote a new admin 1`] = ` Object { "data": Object { "avatarUrl": "http://example.com/avatar.png", - "createdAt": "2018-01-01T00:00:00.000Z", + "createdAt": "2018-01-02T00:00:00.000Z", "email": "user1@example.com", "id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61", "isAdmin": true, @@ -168,7 +168,7 @@ exports[`#users.suspend should suspend an user 1`] = ` Object { "data": Object { "avatarUrl": "http://example.com/avatar.png", - "createdAt": "2018-01-01T00:00:00.000Z", + "createdAt": "2018-01-02T00:00:00.000Z", "email": "user1@example.com", "id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61", "isAdmin": false, @@ -202,7 +202,7 @@ exports[`#users.update should update user profile information 1`] = ` Object { "data": Object { "avatarUrl": "http://example.com/avatar.png", - "createdAt": "2018-01-01T00:00:00.000Z", + "createdAt": "2018-01-02T00:00:00.000Z", "email": "user1@example.com", "id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61", "isAdmin": false, diff --git a/server/api/apiKeys.js b/server/api/apiKeys.js index 43c6d966..95569551 100644 --- a/server/api/apiKeys.js +++ b/server/api/apiKeys.js @@ -49,7 +49,7 @@ router.post('apiKeys.delete', auth(), async ctx => { ctx.assertUuid(id, 'id is required'); const user = ctx.state.user; - const key = await ApiKey.findById(id); + const key = await ApiKey.findByPk(id); authorize(user, 'delete', key); await key.destroy(); diff --git a/server/api/auth.js b/server/api/auth.js index af2c37aa..847abc59 100644 --- a/server/api/auth.js +++ b/server/api/auth.js @@ -8,7 +8,7 @@ const router = new Router(); router.post('auth.info', auth(), async ctx => { const user = ctx.state.user; - const team = await Team.findById(user.teamId); + const team = await Team.findByPk(user.teamId); ctx.body = { data: { diff --git a/server/api/collections.js b/server/api/collections.js index 11ffb625..e5b594d1 100644 --- a/server/api/collections.js +++ b/server/api/collections.js @@ -49,7 +49,7 @@ router.post('collections.info', auth(), async ctx => { const { id } = ctx.body; ctx.assertUuid(id, 'id is required'); - const collection = await Collection.findById(id); + const collection = await Collection.findByPk(id); authorize(ctx.state.user, 'read', collection); ctx.body = { @@ -62,14 +62,14 @@ router.post('collections.add_user', auth(), async ctx => { ctx.assertUuid(id, 'id is required'); ctx.assertUuid(userId, 'userId is required'); - const collection = await Collection.findById(id); + const collection = await Collection.findByPk(id); authorize(ctx.state.user, 'update', collection); if (!collection.private) { throw new InvalidRequestError('Collection must be private to add users'); } - const user = await User.findById(userId); + const user = await User.findByPk(userId); authorize(ctx.state.user, 'read', user); await CollectionUser.create({ @@ -97,14 +97,14 @@ router.post('collections.remove_user', auth(), async ctx => { ctx.assertUuid(id, 'id is required'); ctx.assertUuid(userId, 'userId is required'); - const collection = await Collection.findById(id); + const collection = await Collection.findByPk(id); authorize(ctx.state.user, 'update', collection); if (!collection.private) { throw new InvalidRequestError('Collection must be private to remove users'); } - const user = await User.findById(userId); + const user = await User.findByPk(userId); authorize(ctx.state.user, 'read', user); await collection.removeUser(user); @@ -126,7 +126,7 @@ router.post('collections.users', auth(), async ctx => { const { id } = ctx.body; ctx.assertUuid(id, 'id is required'); - const collection = await Collection.findById(id); + const collection = await Collection.findByPk(id); authorize(ctx.state.user, 'read', collection); const users = await collection.getUsers(); @@ -141,7 +141,7 @@ router.post('collections.export', auth(), async ctx => { ctx.assertUuid(id, 'id is required'); const user = ctx.state.user; - const collection = await Collection.findById(id); + const collection = await Collection.findByPk(id); authorize(user, 'export', collection); // async operation to create zip archive and email user @@ -154,7 +154,7 @@ router.post('collections.export', auth(), async ctx => { router.post('collections.exportAll', auth(), async ctx => { const user = ctx.state.user; - const team = await Team.findById(user.teamId); + const team = await Team.findByPk(user.teamId); authorize(user, 'export', team); // async operation to create zip archive and email user @@ -174,7 +174,7 @@ router.post('collections.update', auth(), async ctx => { ctx.assertHexColor(color, 'Invalid hex value (please use format #FFFFFF)'); const user = ctx.state.user; - const collection = await Collection.findById(id); + const collection = await Collection.findByPk(id); authorize(user, 'update', collection); if (isPrivate && !collection.private) { @@ -237,7 +237,7 @@ router.post('collections.delete', auth(), async ctx => { const user = ctx.state.user; ctx.assertUuid(id, 'id is required'); - const collection = await Collection.findById(id); + const collection = await Collection.findByPk(id); authorize(user, 'delete', collection); const total = await Collection.count(); diff --git a/server/api/documents.js b/server/api/documents.js index 9ecaa2c1..c5ed4057 100644 --- a/server/api/documents.js +++ b/server/api/documents.js @@ -41,7 +41,7 @@ router.post('documents.list', auth(), pagination(), async ctx => { ctx.assertUuid(collectionId, 'collection must be a UUID'); where = { ...where, collectionId }; - const collection = await Collection.findById(collectionId); + const collection = await Collection.findByPk(collectionId); authorize(user, 'read', collection); // otherwise, filter by all collections the user has access to @@ -77,7 +77,7 @@ router.post('documents.pinned', auth(), pagination(), async ctx => { ctx.assertUuid(collectionId, 'collection is required'); const user = ctx.state.user; - const collection = await Collection.findById(collectionId); + const collection = await Collection.findByPk(collectionId); authorize(user, 'read', collection); const starredScope = { method: ['withStarred', user.id] }; @@ -86,7 +86,6 @@ router.post('documents.pinned', auth(), pagination(), async ctx => { teamId: user.teamId, collectionId, pinnedById: { - // $FlowFixMe [Op.ne]: null, }, }, @@ -118,7 +117,6 @@ router.post('documents.archived', auth(), pagination(), async ctx => { teamId: user.teamId, collectionId: collectionIds, archivedAt: { - // $FlowFixMe [Op.ne]: null, }, }, @@ -232,7 +230,6 @@ router.post('documents.drafts', auth(), pagination(), async ctx => { where: { userId: user.id, collectionId: collectionIds, - // $FlowFixMe publishedAt: { [Op.eq]: null }, }, order: [[sort, direction]], @@ -258,9 +255,8 @@ router.post('documents.info', auth({ required: false }), async ctx => { let document; if (shareId) { - const share = await Share.find({ + const share = await Share.findOne({ where: { - // $FlowFixMe revokedAt: { [Op.eq]: null }, id: shareId, }, @@ -277,7 +273,7 @@ router.post('documents.info', auth({ required: false }), async ctx => { } document = share.document; } else { - document = await Document.findById(id); + document = await Document.findByPk(id); authorize(user, 'read', document); } @@ -293,7 +289,7 @@ router.post('documents.revision', auth(), async ctx => { ctx.assertPresent(id, 'id is required'); ctx.assertPresent(revisionId, 'revisionId is required'); - const document = await Document.findById(id); + const document = await Document.findByPk(id); authorize(ctx.state.user, 'read', document); const revision = await Revision.findOne({ @@ -313,7 +309,7 @@ router.post('documents.revisions', auth(), pagination(), async ctx => { let { id, sort = 'updatedAt', direction } = ctx.body; if (direction !== 'ASC') direction = 'DESC'; ctx.assertPresent(id, 'id is required'); - const document = await Document.findById(id); + const document = await Document.findByPk(id); authorize(ctx.state.user, 'read', document); @@ -335,7 +331,7 @@ router.post('documents.restore', auth(), async ctx => { ctx.assertPresent(id, 'id is required'); const user = ctx.state.user; - const document = await Document.findById(id); + const document = await Document.findByPk(id); if (document.archivedAt) { authorize(user, 'unarchive', document); @@ -354,7 +350,7 @@ router.post('documents.restore', auth(), async ctx => { // restore a document to a specific revision authorize(user, 'update', document); - const revision = await Revision.findById(revisionId); + const revision = await Revision.findByPk(revisionId); authorize(document, 'restore', revision); document.text = revision.text; @@ -386,7 +382,7 @@ router.post('documents.search', auth(), pagination(), async ctx => { if (collectionId) { ctx.assertUuid(collectionId, 'collectionId must be a UUID'); - const collection = await Collection.findById(collectionId); + const collection = await Collection.findByPk(collectionId); authorize(user, 'read', collection); } @@ -430,7 +426,7 @@ router.post('documents.pin', auth(), async ctx => { const { id } = ctx.body; ctx.assertPresent(id, 'id is required'); const user = ctx.state.user; - const document = await Document.findById(id); + const document = await Document.findByPk(id); authorize(user, 'update', document); @@ -454,7 +450,7 @@ router.post('documents.unpin', auth(), async ctx => { const { id } = ctx.body; ctx.assertPresent(id, 'id is required'); const user = ctx.state.user; - const document = await Document.findById(id); + const document = await Document.findByPk(id); authorize(user, 'update', document); @@ -478,7 +474,7 @@ router.post('documents.star', auth(), async ctx => { const { id } = ctx.body; ctx.assertPresent(id, 'id is required'); const user = ctx.state.user; - const document = await Document.findById(id); + const document = await Document.findByPk(id); authorize(user, 'read', document); @@ -499,7 +495,7 @@ router.post('documents.unstar', auth(), async ctx => { const { id } = ctx.body; ctx.assertPresent(id, 'id is required'); const user = ctx.state.user; - const document = await Document.findById(id); + const document = await Document.findByPk(id); authorize(user, 'read', document); @@ -590,7 +586,7 @@ router.post('documents.create', auth(), async ctx => { // reload to get all of the data needed to present (user, collection etc) // we need to specify publishedAt to bypass default scope that only returns // published documents - document = await Document.find({ + document = await Document.findOne({ where: { id: document.id, publishedAt: document.publishedAt }, }); @@ -615,7 +611,7 @@ router.post('documents.update', auth(), async ctx => { if (append) ctx.assertPresent(text, 'Text is required while appending'); const user = ctx.state.user; - const document = await Document.findById(id); + const document = await Document.findByPk(id); authorize(ctx.state.user, 'update', document); @@ -680,10 +676,10 @@ router.post('documents.move', auth(), async ctx => { } const user = ctx.state.user; - const document = await Document.findById(id); + const document = await Document.findByPk(id); authorize(user, 'move', document); - const collection = await Collection.findById(collectionId); + const collection = await Collection.findByPk(collectionId); authorize(user, 'update', collection); if (collection.type !== 'atlas' && parentDocumentId) { @@ -693,7 +689,7 @@ router.post('documents.move', auth(), async ctx => { } if (parentDocumentId) { - const parent = await Document.findById(parentDocumentId); + const parent = await Document.findByPk(parentDocumentId); authorize(user, 'update', parent); } @@ -721,7 +717,7 @@ router.post('documents.archive', auth(), async ctx => { ctx.assertPresent(id, 'id is required'); const user = ctx.state.user; - const document = await Document.findById(id); + const document = await Document.findByPk(id); authorize(user, 'archive', document); await document.archive(user.id); @@ -744,7 +740,7 @@ router.post('documents.delete', auth(), async ctx => { ctx.assertPresent(id, 'id is required'); const user = ctx.state.user; - const document = await Document.findById(id); + const document = await Document.findByPk(id); authorize(user, 'delete', document); await document.delete(); diff --git a/server/api/documents.test.js b/server/api/documents.test.js index 041964d2..8f616a07 100644 --- a/server/api/documents.test.js +++ b/server/api/documents.test.js @@ -66,10 +66,11 @@ describe('#documents.info', async () => { }); it('should return document from shareId without token', async () => { - const { document } = await seed(); + const { document, user } = await seed(); const share = await buildShare({ documentId: document.id, teamId: document.teamId, + userId: user.id, }); const res = await server.post('/api/documents.info', { @@ -88,6 +89,7 @@ describe('#documents.info', async () => { const share = await buildShare({ documentId: document.id, teamId: document.teamId, + userId: user.id, }); await share.revoke(user.id); @@ -102,6 +104,7 @@ describe('#documents.info', async () => { const share = await buildShare({ documentId: document.id, teamId: document.teamId, + userId: user.id, }); await document.archive(user.id); @@ -116,6 +119,7 @@ describe('#documents.info', async () => { const share = await buildShare({ documentId: document.id, teamId: document.teamId, + userId: user.id, }); const res = await server.post('/api/documents.info', { @@ -134,6 +138,7 @@ describe('#documents.info', async () => { const share = await buildShare({ documentId: document.id, teamId: document.teamId, + userId: user.id, }); collection.private = true; @@ -974,7 +979,7 @@ describe('#documents.create', async () => { }, }); const body = await res.json(); - const newDocument = await Document.findById(body.data.id); + const newDocument = await Document.findByPk(body.data.id); expect(res.status).toEqual(200); expect(newDocument.parentDocumentId).toBe(null); expect(newDocument.collection.id).toBe(collection.id); diff --git a/server/api/hooks.js b/server/api/hooks.js index 45c1f0fb..f89cfad6 100644 --- a/server/api/hooks.js +++ b/server/api/hooks.js @@ -12,15 +12,16 @@ router.post('hooks.unfurl', async ctx => { const { challenge, token, event } = ctx.body; if (challenge) return (ctx.body = ctx.body.challenge); - if (token !== process.env.SLACK_VERIFICATION_TOKEN) + if (token !== process.env.SLACK_VERIFICATION_TOKEN) { throw new AuthenticationError('Invalid token'); + } - const user = await User.find({ + const user = await User.findOne({ where: { service: 'slack', serviceId: event.user }, }); if (!user) return; - const auth = await Authentication.find({ + const auth = await Authentication.findOne({ where: { service: 'slack', teamId: user.teamId }, }); if (!auth) return; @@ -29,7 +30,7 @@ router.post('hooks.unfurl', async ctx => { let unfurls = {}; for (let link of event.links) { const id = link.url.substr(link.url.lastIndexOf('/') + 1); - const doc = await Document.findById(id); + const doc = await Document.findByPk(id); if (!doc || doc.teamId !== user.teamId) continue; unfurls[link.url] = { @@ -60,7 +61,7 @@ router.post('hooks.interactive', async ctx => { if (token !== process.env.SLACK_VERIFICATION_TOKEN) throw new AuthenticationError('Invalid verification token'); - const user = await User.find({ + const user = await User.findOne({ where: { service: 'slack', serviceId: data.user.id }, }); if (!user) { @@ -73,12 +74,12 @@ router.post('hooks.interactive', async ctx => { } // we find the document based on the users teamId to ensure access - const document = await Document.find({ + const document = await Document.findOne({ where: { id: data.callback_id, teamId: user.teamId }, }); if (!document) throw new InvalidRequestError('Invalid document'); - const team = await Team.findById(user.teamId); + const team = await Team.findByPk(user.teamId); // respond with a public message that will be posted in the original channel ctx.body = { @@ -100,7 +101,7 @@ router.post('hooks.slack', async ctx => { if (token !== process.env.SLACK_VERIFICATION_TOKEN) throw new AuthenticationError('Invalid verification token'); - const user = await User.find({ + const user = await User.findOne({ where: { service: 'slack', serviceId: user_id, @@ -113,7 +114,7 @@ router.post('hooks.slack', async ctx => { return; } - const team = await Team.findById(user.teamId); + const team = await Team.findByPk(user.teamId); const results = await Document.searchForUser(user, text, { limit: 5, }); diff --git a/server/api/integrations.js b/server/api/integrations.js index 01ed9d42..6eb6eb93 100644 --- a/server/api/integrations.js +++ b/server/api/integrations.js @@ -33,7 +33,7 @@ router.post('integrations.delete', auth(), async ctx => { ctx.assertUuid(id, 'id is required'); const user = ctx.state.user; - const integration = await Integration.findById(id); + const integration = await Integration.findByPk(id); authorize(user, 'delete', integration); await integration.destroy(); diff --git a/server/api/notificationSettings.js b/server/api/notificationSettings.js index a137c216..cad6d761 100644 --- a/server/api/notificationSettings.js +++ b/server/api/notificationSettings.js @@ -47,7 +47,7 @@ router.post('notificationSettings.delete', auth(), async ctx => { ctx.assertUuid(id, 'id is required'); const user = ctx.state.user; - const setting = await NotificationSetting.findById(id); + const setting = await NotificationSetting.findByPk(id); authorize(user, 'delete', setting); await setting.destroy(); @@ -62,7 +62,7 @@ router.post('notificationSettings.unsubscribe', async ctx => { ctx.assertUuid(id, 'id is required'); ctx.assertPresent(token, 'token is required'); - const setting = await NotificationSetting.findById(id); + const setting = await NotificationSetting.findByPk(id); if (setting) { if (token !== setting.unsubscribeToken) { ctx.redirect(`${process.env.URL}?notice=invalid-auth`); diff --git a/server/api/shares.js b/server/api/shares.js index 24ade2c9..d66ec48c 100644 --- a/server/api/shares.js +++ b/server/api/shares.js @@ -19,11 +19,12 @@ router.post('shares.list', auth(), pagination(), async ctx => { const where = { teamId: user.teamId, userId: user.id, - // $FlowFixMe revokedAt: { [Op.eq]: null }, }; - if (user.isAdmin) delete where.userId; + if (user.isAdmin) { + delete where.userId; + } const collectionIds = await user.collectionIds(); const shares = await Share.findAll({ @@ -58,8 +59,8 @@ router.post('shares.create', auth(), async ctx => { ctx.assertPresent(documentId, 'documentId is required'); const user = ctx.state.user; - const document = await Document.findById(documentId); - const team = await Team.findById(user.teamId); + const document = await Document.findByPk(documentId); + const team = await Team.findByPk(user.teamId); authorize(user, 'share', document); authorize(user, 'share', team); @@ -85,7 +86,7 @@ router.post('shares.revoke', auth(), async ctx => { ctx.assertUuid(id, 'id is required'); const user = ctx.state.user; - const share = await Share.findById(id); + const share = await Share.findByPk(id); authorize(user, 'revoke', share); await share.revoke(user.id); diff --git a/server/api/shares.test.js b/server/api/shares.test.js index c563bfb1..0a84be49 100644 --- a/server/api/shares.test.js +++ b/server/api/shares.test.js @@ -11,10 +11,11 @@ afterAll(server.close); describe('#shares.list', async () => { it('should only return shares created by user', async () => { - const { user, document } = await seed(); + const { user, admin, document } = await seed(); await buildShare({ documentId: document.id, teamId: user.teamId, + userId: admin.id, }); const share = await buildShare({ documentId: document.id, @@ -51,10 +52,11 @@ describe('#shares.list', async () => { }); it('admins should return shares created by all users', async () => { - const { admin, document } = await seed(); + const { user, admin, document } = await seed(); const share = await buildShare({ documentId: document.id, teamId: admin.teamId, + userId: user.id, }); const res = await server.post('/api/shares.list', { body: { token: admin.getJwtToken() }, @@ -72,6 +74,7 @@ describe('#shares.list', async () => { await buildShare({ documentId: document.id, teamId: admin.teamId, + userId: admin.id, }); collection.private = true; diff --git a/server/api/team.js b/server/api/team.js index 31265ee9..feffcc31 100644 --- a/server/api/team.js +++ b/server/api/team.js @@ -15,7 +15,7 @@ router.post('team.update', auth(), async ctx => { const endpoint = publicS3Endpoint(); const user = ctx.state.user; - const team = await Team.findById(user.teamId); + const team = await Team.findByPk(user.teamId); authorize(user, 'update', team); if (process.env.SUBDOMAINS_ENABLED === 'true') { diff --git a/server/api/users.js b/server/api/users.js index 8dc8f235..f35cc1ee 100644 --- a/server/api/users.js +++ b/server/api/users.js @@ -119,10 +119,10 @@ router.post('users.promote', auth(), async ctx => { const teamId = ctx.state.user.teamId; ctx.assertPresent(userId, 'id is required'); - const user = await User.findById(userId); + const user = await User.findByPk(userId); authorize(ctx.state.user, 'promote', user); - const team = await Team.findById(teamId); + const team = await Team.findByPk(teamId); await team.addAdmin(user); ctx.body = { @@ -135,10 +135,10 @@ router.post('users.demote', auth(), async ctx => { const teamId = ctx.state.user.teamId; ctx.assertPresent(userId, 'id is required'); - const user = await User.findById(userId); + const user = await User.findByPk(userId); authorize(ctx.state.user, 'demote', user); - const team = await Team.findById(teamId); + const team = await Team.findByPk(teamId); try { await team.removeAdmin(user); } catch (err) { @@ -161,10 +161,10 @@ router.post('users.suspend', auth(), async ctx => { const teamId = ctx.state.user.teamId; ctx.assertPresent(userId, 'id is required'); - const user = await User.findById(userId); + const user = await User.findByPk(userId); authorize(ctx.state.user, 'suspend', user); - const team = await Team.findById(teamId); + const team = await Team.findByPk(teamId); try { await team.suspendUser(user, admin); } catch (err) { @@ -188,10 +188,10 @@ router.post('users.activate', auth(), async ctx => { const teamId = ctx.state.user.teamId; ctx.assertPresent(userId, 'id is required'); - const user = await User.findById(userId); + const user = await User.findByPk(userId); authorize(ctx.state.user, 'activate', user); - const team = await Team.findById(teamId); + const team = await Team.findByPk(teamId); await team.activateUser(user, admin); ctx.body = { diff --git a/server/api/views.js b/server/api/views.js index c8d88824..b148a141 100644 --- a/server/api/views.js +++ b/server/api/views.js @@ -13,7 +13,7 @@ router.post('views.list', auth(), async ctx => { ctx.assertUuid(documentId, 'documentId is required'); const user = ctx.state.user; - const document = await Document.findById(documentId); + const document = await Document.findByPk(documentId); authorize(user, 'read', document); const views = await View.findAll({ @@ -37,7 +37,7 @@ router.post('views.create', auth(), async ctx => { ctx.assertUuid(documentId, 'documentId is required'); const user = ctx.state.user; - const document = await Document.findById(documentId); + const document = await Document.findByPk(documentId); authorize(user, 'read', document); await View.increment({ documentId, userId: user.id }); diff --git a/server/auth/index.js b/server/auth/index.js index 37317c82..3d13d5ae 100644 --- a/server/auth/index.js +++ b/server/auth/index.js @@ -31,7 +31,7 @@ router.get('/redirect', auth(), async ctx => { expires: addMonths(new Date(), 3), }); - const team = await Team.findById(user.teamId); + const team = await Team.findByPk(user.teamId); ctx.redirect(`${team.url}/dashboard`); }); diff --git a/server/auth/slack.js b/server/auth/slack.js index d3ffce1f..6b39ede2 100644 --- a/server/auth/slack.js +++ b/server/auth/slack.js @@ -89,7 +89,7 @@ router.get('slack.commands', auth({ required: false }), async ctx => { if (!user) { if (state) { try { - const team = await Team.findById(state); + const team = await Team.findByPk(state); return ctx.redirect( `${team.url}/auth${ctx.request.path}?${ctx.request.querystring}` ); @@ -143,8 +143,8 @@ router.get('slack.post', auth({ required: false }), async ctx => { // appropriate subdomain to complete the oauth flow if (!user) { try { - const collection = await Collection.findById(state); - const team = await Team.findById(collection.teamId); + const collection = await Collection.findByPk(state); + const team = await Team.findByPk(collection.teamId); return ctx.redirect( `${team.url}/auth${ctx.request.path}?${ctx.request.querystring}` ); diff --git a/server/commands/documentMover.js b/server/commands/documentMover.js index eb41df64..834b1348 100644 --- a/server/commands/documentMover.js +++ b/server/commands/documentMover.js @@ -36,7 +36,7 @@ export default async function documentMover({ document.parentDocumentId = parentDocumentId; const newCollection: Collection = collectionChanged - ? await Collection.findById(collectionId, { transaction }) + ? await Collection.findByPk(collectionId, { transaction }) : collection; await newCollection.addDocumentToStructure(document, index, { documentJson, diff --git a/server/index.js b/server/index.js index 8be0a462..a130d17b 100644 --- a/server/index.js +++ b/server/index.js @@ -53,7 +53,7 @@ if (process.env.WEBSOCKETS_ENABLED === 'true') { // allow the client to request to join rooms based on // new collections being created. socket.on('join', async event => { - const collection = await Collection.findById(event.roomId); + const collection = await Collection.findByPk(event.roomId); if (can(user, 'read', collection)) { socket.join(`collection-${event.roomId}`); diff --git a/server/logistics.js b/server/logistics.js index d1136ebb..c9f21ba7 100644 --- a/server/logistics.js +++ b/server/logistics.js @@ -18,7 +18,7 @@ const queueOptions = { async function exportAndEmailCollection(collectionId: string, email: string) { log('Archiving collection', collectionId); - const collection = await Collection.findById(collectionId); + const collection = await Collection.findByPk(collectionId); const filePath = await archiveCollection(collection); log('Archive path', filePath); @@ -36,7 +36,7 @@ async function exportAndEmailCollection(collectionId: string, email: string) { async function exportAndEmailCollections(teamId: string, email: string) { log('Archiving team', teamId); - const team = await Team.findById(teamId); + const team = await Team.findByPk(teamId); const collections = await Collection.findAll({ where: { teamId }, order: [['name', 'ASC']], diff --git a/server/middlewares/authentication.js b/server/middlewares/authentication.js index 68a850de..16c9adc7 100644 --- a/server/middlewares/authentication.js +++ b/server/middlewares/authentication.js @@ -57,7 +57,7 @@ export default function auth(options?: { required?: boolean } = {}) { if (!apiKey) throw new AuthenticationError('Invalid API key'); - user = await User.findById(apiKey.userId); + user = await User.findByPk(apiKey.userId); if (!user) throw new AuthenticationError('Invalid API key'); } else { // JWT diff --git a/server/migrations/20170712055148-non-unique-email.js b/server/migrations/20170712055148-non-unique-email.js index f4547039..169c0c69 100644 --- a/server/migrations/20170712055148-non-unique-email.js +++ b/server/migrations/20170712055148-non-unique-email.js @@ -1,7 +1,15 @@ module.exports = { up: async (queryInterface, Sequelize) => { - await queryInterface.removeConstraint('users', 'email_unique_idx'); - await queryInterface.removeConstraint('users', 'username_unique_idx'); + await queryInterface.changeColumn('users', 'email', { + type: Sequelize.STRING, + unique: false, + allowNull: false, + }); + await queryInterface.changeColumn('users', 'username', { + type: Sequelize.STRING, + unique: false, + allowNull: false, + }); }, down: async (queryInterface, Sequelize) => { diff --git a/server/models/Document.js b/server/models/Document.js index a76d488c..810a078f 100644 --- a/server/models/Document.js +++ b/server/models/Document.js @@ -156,7 +156,6 @@ Document.associate = models => { ], where: { publishedAt: { - // $FlowFixMe [Op.ne]: null, }, }, @@ -182,7 +181,7 @@ Document.associate = models => { })); }; -Document.findById = async (id, options) => { +Document.findByPk = async (id, options) => { const scope = Document.scope('withUnpublished'); if (isUUID(id)) { @@ -300,7 +299,7 @@ Document.searchForUser = async ( Document.addHook('beforeSave', async model => { if (!model.publishedAt) return; - const collection = await Collection.findById(model.collectionId); + const collection = await Collection.findByPk(model.collectionId); if (!collection || collection.type !== 'atlas') return; await collection.updateDocument(model); @@ -310,7 +309,7 @@ Document.addHook('beforeSave', async model => { Document.addHook('afterCreate', async model => { if (!model.publishedAt) return; - const collection = await Collection.findById(model.collectionId); + const collection = await Collection.findByPk(model.collectionId); if (!collection || collection.type !== 'atlas') return; await collection.addDocumentToStructure(model); @@ -366,7 +365,7 @@ Document.prototype.archiveWithChildren = async function(userId, options) { Document.prototype.publish = async function() { if (this.publishedAt) return this.save(); - const collection = await Collection.findById(this.collectionId); + const collection = await Collection.findByPk(this.collectionId); if (collection.type !== 'atlas') return this.save(); await collection.addDocumentToStructure(this); @@ -402,7 +401,6 @@ Document.prototype.unarchive = async function(userId) { where: { id: this.parentDocumentId, archivedAt: { - // $FlowFixMe [Op.eq]: null, }, }, diff --git a/server/models/Team.js b/server/models/Team.js index 07a4255f..5686bda0 100644 --- a/server/models/Team.js +++ b/server/models/Team.js @@ -131,7 +131,6 @@ Team.prototype.removeAdmin = async function(user: User) { teamId: this.id, isAdmin: true, id: { - // $FlowFixMe [Op.ne]: user.id, }, }, diff --git a/server/models/User.js b/server/models/User.js index e5ef8d4c..22d18b56 100644 --- a/server/models/User.js +++ b/server/models/User.js @@ -159,7 +159,7 @@ User.beforeDestroy(removeIdentifyingInfo); User.beforeSave(uploadAvatar); User.beforeCreate(setRandomJwtSecret); User.afterCreate(async user => { - const team = await Team.findById(user.teamId); + const team = await Team.findByPk(user.teamId); sendEmail('welcome', user.email, { teamUrl: team.url }); }); diff --git a/server/routes.js b/server/routes.js index 9a3386c4..be977bf2 100644 --- a/server/routes.js +++ b/server/routes.js @@ -113,7 +113,7 @@ router.get('/', async ctx => { ) { const domain = parseDomain(ctx.request.hostname); const subdomain = domain ? domain.subdomain : undefined; - const team = await Team.find({ + const team = await Team.findOne({ where: { subdomain }, }); if (team) { diff --git a/server/sequelize.js b/server/sequelize.js index 83c05954..f0f7fd5e 100644 --- a/server/sequelize.js +++ b/server/sequelize.js @@ -3,9 +3,10 @@ import Sequelize from 'sequelize'; import EncryptedField from 'sequelize-encrypted'; import debug from 'debug'; -const secretKey = process.env.SECRET_KEY; - -export const encryptedFields = EncryptedField(Sequelize, secretKey); +export const encryptedFields = EncryptedField( + Sequelize, + process.env.SECRET_KEY +); export const DataTypes = Sequelize; export const Op = Sequelize.Op; @@ -13,5 +14,4 @@ export const Op = Sequelize.Op; export const sequelize = new Sequelize(process.env.DATABASE_URL, { logging: debug('sql'), typeValidation: true, - operatorsAliases: false, }); diff --git a/server/services/notifications.js b/server/services/notifications.js index 22b53bc3..521d5757 100644 --- a/server/services/notifications.js +++ b/server/services/notifications.js @@ -23,7 +23,7 @@ export default class Notifications { // wait until the user has finished editing if (!event.done) return; - const document = await Document.findById(event.modelId); + const document = await Document.findByPk(event.modelId); if (!document) return; const { collection } = document; @@ -32,7 +32,6 @@ export default class Notifications { const notificationSettings = await NotificationSetting.findAll({ where: { userId: { - // $FlowFixMe [Op.ne]: document.lastModifiedById, }, teamId: document.teamId, @@ -73,7 +72,7 @@ export default class Notifications { } async collectionCreated(event: Event) { - const collection = await Collection.findById(event.modelId, { + const collection = await Collection.findByPk(event.modelId, { include: [ { model: User, @@ -88,7 +87,6 @@ export default class Notifications { const notificationSettings = await NotificationSetting.findAll({ where: { userId: { - // $FlowFixMe [Op.ne]: collection.createdById, }, teamId: collection.teamId, diff --git a/server/services/slack.js b/server/services/slack.js index e016b3cb..a85cfbe3 100644 --- a/server/services/slack.js +++ b/server/services/slack.js @@ -60,7 +60,7 @@ export default class Slack { // lets not send a notification on every autosave update if (event.autosave) return; - const document = await Document.findById(event.modelId); + const document = await Document.findByPk(event.modelId); if (!document) return; // never send information on draft documents @@ -76,7 +76,7 @@ export default class Slack { }); if (!integration) return; - const team = await Team.findById(document.teamId); + const team = await Team.findByPk(document.teamId); let text = `${document.createdBy.name} published a new document`; diff --git a/server/services/websockets.js b/server/services/websockets.js index f2210911..0445f111 100644 --- a/server/services/websockets.js +++ b/server/services/websockets.js @@ -17,7 +17,7 @@ export default class Websockets { case 'documents.unpin': case 'documents.update': case 'documents.delete': { - const document = await Document.findById(event.modelId, { + const document = await Document.findByPk(event.modelId, { paranoid: false, }); const documents = [await presentDocument(document)]; @@ -32,7 +32,7 @@ export default class Websockets { }); } case 'documents.create': { - const document = await Document.findById(event.modelId); + const document = await Document.findByPk(event.modelId); const documents = [await presentDocument(document)]; const collections = [await presentCollection(document.collection)]; @@ -78,7 +78,7 @@ export default class Websockets { return; } case 'collections.create': { - const collection = await Collection.findById(event.modelId, { + const collection = await Collection.findByPk(event.modelId, { paranoid: false, }); const collections = [await presentCollection(collection)]; @@ -106,7 +106,7 @@ export default class Websockets { } case 'collections.update': case 'collections.delete': { - const collection = await Collection.findById(event.modelId, { + const collection = await Collection.findByPk(event.modelId, { paranoid: false, }); const collections = [await presentCollection(collection)]; diff --git a/server/test/support.js b/server/test/support.js index b7f46887..dbedbc5f 100644 --- a/server/test/support.js +++ b/server/test/support.js @@ -23,21 +23,6 @@ const seed = async () => { }, }); - const user = await User.create({ - id: '46fde1d4-0050-428f-9f0b-0bf77f4bdf61', - email: 'user1@example.com', - username: 'user1', - name: 'User 1', - teamId: team.id, - service: 'slack', - serviceId: 'U2399UF2P', - slackData: { - id: 'U2399UF2P', - image_192: 'http://example.com/avatar.png', - }, - createdAt: new Date('2018-01-01T00:00:00.000Z'), - }); - const admin = await User.create({ id: 'fa952cff-fa64-4d42-a6ea-6955c9689046', email: 'admin@example.com', @@ -54,6 +39,21 @@ const seed = async () => { createdAt: new Date('2018-01-01T00:00:00.000Z'), }); + const user = await User.create({ + id: '46fde1d4-0050-428f-9f0b-0bf77f4bdf61', + email: 'user1@example.com', + username: 'user1', + name: 'User 1', + teamId: team.id, + service: 'slack', + serviceId: 'U2399UF2P', + slackData: { + id: 'U2399UF2P', + image_192: 'http://example.com/avatar.png', + }, + createdAt: new Date('2018-01-02T00:00:00.000Z'), + }); + const collection = await Collection.create({ id: '26fde1d4-0050-428f-9f0b-0bf77f8bdf62', name: 'Collection', diff --git a/server/utils/jwt.js b/server/utils/jwt.js index ead58e7f..0ef785c4 100644 --- a/server/utils/jwt.js +++ b/server/utils/jwt.js @@ -13,7 +13,7 @@ export async function getUserForJWT(token: string) { if (!payload) throw new AuthenticationError('Invalid token'); - const user = await User.findById(payload.id); + const user = await User.findByPk(payload.id); try { JWT.verify(token, user.jwtSecret); diff --git a/server/utils/zip.js b/server/utils/zip.js index 298d6fd5..f4cbfe03 100644 --- a/server/utils/zip.js +++ b/server/utils/zip.js @@ -7,7 +7,7 @@ import { Collection, Document } from '../models'; async function addToArchive(zip, documents) { for (const doc of documents) { - const document = await Document.findById(doc.id); + const document = await Document.findByPk(doc.id); zip.file(`${document.title}.md`, unescape(document.text)); diff --git a/yarn.lock b/yarn.lock index 78e3ead0..0ddef90b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -132,10 +132,6 @@ version "0.19.0-0" resolved "https://registry.yarnpkg.com/@tommoor/slate-edit-list/-/slate-edit-list-0.19.0-0.tgz#972a714e9ea4cdf47a530d5702a904f5547be2dd" -"@types/geojson@^1.0.0": - version "1.0.6" - resolved "https://registry.yarnpkg.com/@types/geojson/-/geojson-1.0.6.tgz#3e02972728c69248c2af08d60a48cbb8680fffdf" - "@types/node@*": version "11.10.4" resolved "https://registry.yarnpkg.com/@types/node/-/node-11.10.4.tgz#3f5fc4f0f322805f009e00ab35a2ff3d6b778e42" @@ -304,6 +300,10 @@ ansi-regex@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.0.0.tgz#70de791edf021404c3fd615aa89118ae0432e5a9" +ansi-regex@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997" + ansi-styles@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" @@ -314,7 +314,7 @@ ansi-styles@^3.2.0, ansi-styles@^3.2.1: dependencies: color-convert "^1.9.0" -any-promise@^1.0.0, any-promise@^1.1.0: +any-promise@^1.0.0, any-promise@^1.1.0, any-promise@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f" @@ -1287,10 +1287,14 @@ blob@0.0.5: version "0.0.5" resolved "https://registry.yarnpkg.com/blob/-/blob-0.0.5.tgz#d680eeef25f8cd91ad533f5b01eed48e64caf683" -bluebird@^3.3.5, bluebird@^3.4.6, bluebird@^3.5.1, bluebird@^3.5.3: +bluebird@^3.3.5, bluebird@^3.5.1, bluebird@^3.5.3: version "3.5.3" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.3.tgz#7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7" +bluebird@^3.5.0: + version "3.5.5" + resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.5.tgz#a8d0afd73251effbbd5fe384a77d73003c17a71f" + bluebird@~3.4.1: version "3.4.7" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.4.7.tgz#f72d760be09b7f76d08ed8fae98b289a8d05fab3" @@ -1877,6 +1881,14 @@ cliui@^4.0.0: strip-ansi "^4.0.0" wrap-ansi "^2.0.0" +cliui@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-5.0.0.tgz#deefcfdb2e800784aa34f46fa08e06851c7bbbc5" + dependencies: + string-width "^3.1.0" + strip-ansi "^5.2.0" + wrap-ansi "^5.1.0" + clone-buffer@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/clone-buffer/-/clone-buffer-1.0.0.tgz#e3e25b207ac4e701af721e2cb5a16792cac3dc58" @@ -1901,7 +1913,7 @@ cloneable-readable@^1.0.0: process-nextick-args "^2.0.0" readable-stream "^2.3.5" -cls-bluebird@^2.0.1: +cls-bluebird@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/cls-bluebird/-/cls-bluebird-2.1.0.tgz#37ef1e080a8ffb55c2f4164f536f1919e7968aee" dependencies: @@ -2437,7 +2449,7 @@ debug@^2.1.2, debug@^2.1.3, debug@^2.2.0, debug@^2.3.3, debug@^2.6.1, debug@^2.6 dependencies: ms "2.0.0" -debug@^3.0.0, debug@^3.1.0, debug@^3.2.6: +debug@^3.1.0, debug@^3.2.6: version "3.2.6" resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b" dependencies: @@ -2528,7 +2540,7 @@ depd@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/depd/-/depd-2.0.0.tgz#b696163cc757560d09cf22cc8fad1571b79e76df" -depd@^1.1.0, depd@^1.1.2, depd@~1.1.2: +depd@^1.1.2, depd@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9" @@ -3671,14 +3683,14 @@ generic-pool@2.4.3: version "2.4.3" resolved "https://registry.yarnpkg.com/generic-pool/-/generic-pool-2.4.3.tgz#780c36f69dfad05a5a045dd37be7adca11a4f6ff" -generic-pool@^3.1.8: - version "3.6.1" - resolved "https://registry.yarnpkg.com/generic-pool/-/generic-pool-3.6.1.tgz#a51a8439ee86f0bbcf100fc1db3f45c86289deb4" - get-caller-file@^1.0.1: version "1.0.3" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a" +get-caller-file@^2.0.1: + version "2.0.5" + resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" + get-document@1: version "1.0.0" resolved "https://registry.yarnpkg.com/get-document/-/get-document-1.0.0.tgz#4821bce66f1c24cb0331602be6cb6b12c4f01c4b" @@ -5665,7 +5677,7 @@ lodash.uniq@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" -"lodash@>=3.5 <5", lodash@^4.1.1, lodash@^4.11.1, lodash@^4.17.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.6.1: +"lodash@>=3.5 <5", lodash@^4.1.1, lodash@^4.11.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.6.1: version "4.17.11" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" @@ -5993,13 +6005,19 @@ mobx@4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/mobx/-/mobx-4.6.0.tgz#88a8ed21ff81b8861778c4b0d38e3dcdd1a7ddde" -moment-timezone@^0.5.23, moment-timezone@^0.5.4: +moment-timezone@^0.5.21: + version "0.5.25" + resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.25.tgz#a11bfa2f74e088327f2cd4c08b3e7bdf55957810" + dependencies: + moment ">= 2.9.0" + +moment-timezone@^0.5.23: version "0.5.23" resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.23.tgz#7cbb00db2c14c71b19303cb47b0fb0a6d8651463" dependencies: moment ">= 2.9.0" -"moment@>= 2.9.0", moment@^2.13.0: +"moment@>= 2.9.0", moment@^2.24.0: version "2.24.0" resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b" @@ -6415,7 +6433,7 @@ os-locale@^2.0.0: lcid "^1.0.0" mem "^1.1.0" -os-locale@^3.0.0: +os-locale@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/os-locale/-/os-locale-3.1.0.tgz#a802a6ee17f24c10483ab9935719cef4ed16bf1a" dependencies: @@ -7791,6 +7809,10 @@ require-main-filename@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" +require-main-filename@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" + require-package-name@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/require-package-name/-/require-package-name-2.0.1.tgz#c11e97276b65b8e2923f75dabf5fb2ef0c3841b9" @@ -7845,12 +7867,11 @@ ret@~0.1.10: version "0.1.15" resolved "https://registry.yarnpkg.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc" -retry-as-promised@^2.3.1: - version "2.3.2" - resolved "https://registry.yarnpkg.com/retry-as-promised/-/retry-as-promised-2.3.2.tgz#cd974ee4fd9b5fe03cbf31871ee48221c07737b7" +retry-as-promised@^3.1.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/retry-as-promised/-/retry-as-promised-3.2.0.tgz#769f63d536bec4783549db0777cb56dadd9d8543" dependencies: - bluebird "^3.4.6" - debug "^2.6.9" + any-promise "^1.3.0" retry-axios@0.3.2, retry-axios@^0.3.2: version "0.3.2" @@ -8030,7 +8051,7 @@ semver-diff@^2.0.0: dependencies: semver "^5.0.3" -"semver@2 || 3 || 4 || 5", semver@^5.0.1, semver@^5.0.3, semver@^5.1.0, semver@^5.3.0, semver@^5.5.0, semver@^5.5.1, semver@^5.6.0: +"semver@2 || 3 || 4 || 5", semver@^5.0.3, semver@^5.1.0, semver@^5.3.0, semver@^5.5.0, semver@^5.5.1, semver@^5.6.0: version "5.6.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.6.0.tgz#7e74256fbaa49c75aa7c7a205cc22799cac80004" @@ -8042,6 +8063,10 @@ semver@5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f" +semver@^6.1.1: + version "6.1.1" + resolved "https://registry.yarnpkg.com/semver/-/semver-6.1.1.tgz#53f53da9b30b2103cd4f15eab3a18ecbcb210c9b" + sentence-case@^2.1.0: version "2.1.1" resolved "https://registry.yarnpkg.com/sentence-case/-/sentence-case-2.1.1.tgz#1f6e2dda39c168bf92d13f86d4a918933f667ed4" @@ -8049,9 +8074,9 @@ sentence-case@^2.1.0: no-case "^2.2.0" upper-case-first "^1.1.2" -sequelize-cli@^5.4.0: - version "5.4.0" - resolved "https://registry.yarnpkg.com/sequelize-cli/-/sequelize-cli-5.4.0.tgz#6a2c2af331466414d8b2ecb6912e24d2de0d04b5" +sequelize-cli@^5.5.0: + version "5.5.0" + resolved "https://registry.yarnpkg.com/sequelize-cli/-/sequelize-cli-5.5.0.tgz#b0570352f70eaa489a25dccf55cf316675d6ff06" dependencies: bluebird "^3.5.3" cli-color "^1.4.0" @@ -8060,33 +8085,35 @@ sequelize-cli@^5.4.0: lodash "^4.17.5" resolve "^1.5.0" umzug "^2.1.0" - yargs "^12.0.5" + yargs "^13.1.0" -sequelize-encrypted@0.1.0: +sequelize-encrypted@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/sequelize-encrypted/-/sequelize-encrypted-0.1.0.tgz#f9c7a94dc1b4413e1347a49f06cd07b7f3bf9916" -sequelize@4.28.6: - version "4.28.6" - resolved "https://registry.yarnpkg.com/sequelize/-/sequelize-4.28.6.tgz#44b4b69f550bc53f41135bf8db73c5d492cb7e64" +sequelize-pool@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/sequelize-pool/-/sequelize-pool-2.2.0.tgz#fd4eb05ccefb5df5c23d2cc6fd934c20fd9c5dab" + +sequelize@^5.8.12: + version "5.8.12" + resolved "https://registry.yarnpkg.com/sequelize/-/sequelize-5.8.12.tgz#91f46f16789307d40c68f8c039c10d1d0f230ad2" dependencies: - bluebird "^3.4.6" - cls-bluebird "^2.0.1" - debug "^3.0.0" - depd "^1.1.0" + bluebird "^3.5.0" + cls-bluebird "^2.1.0" + debug "^4.1.1" dottie "^2.0.0" - generic-pool "^3.1.8" inflection "1.12.0" - lodash "^4.17.1" - moment "^2.13.0" - moment-timezone "^0.5.4" - retry-as-promised "^2.3.1" - semver "^5.0.1" - terraformer-wkt-parser "^1.1.2" + lodash "^4.17.11" + moment "^2.24.0" + moment-timezone "^0.5.21" + retry-as-promised "^3.1.0" + semver "^6.1.1" + sequelize-pool "^2.2.0" toposort-class "^1.0.1" - uuid "^3.0.0" - validator "^9.1.0" - wkx "^0.4.1" + uuid "^3.2.1" + validator "^10.11.0" + wkx "^0.4.6" serialize-javascript@^1.4.0: version "1.6.1" @@ -8623,6 +8650,14 @@ string-width@^3.0.0: is-fullwidth-code-point "^2.0.0" strip-ansi "^5.0.0" +string-width@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961" + dependencies: + emoji-regex "^7.0.1" + is-fullwidth-code-point "^2.0.0" + strip-ansi "^5.1.0" + string_decoder@^1.0.0, string_decoder@^1.1.1: version "1.2.0" resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.2.0.tgz#fe86e738b19544afe70469243b2a1ee9240eae8d" @@ -8657,6 +8692,12 @@ strip-ansi@^5.0.0: dependencies: ansi-regex "^4.0.0" +strip-ansi@^5.1.0, strip-ansi@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae" + dependencies: + ansi-regex "^4.1.0" + strip-bom@3.0.0, strip-bom@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" @@ -8808,19 +8849,6 @@ term-size@^1.2.0: dependencies: execa "^0.7.0" -terraformer-wkt-parser@^1.1.2: - version "1.2.0" - resolved "https://registry.yarnpkg.com/terraformer-wkt-parser/-/terraformer-wkt-parser-1.2.0.tgz#c9d6ac3dff25f4c0bd344e961f42694961834c34" - dependencies: - "@types/geojson" "^1.0.0" - terraformer "~1.0.5" - -terraformer@~1.0.5: - version "1.0.9" - resolved "https://registry.yarnpkg.com/terraformer/-/terraformer-1.0.9.tgz#77851fef4a49c90b345dc53cf26809fdf29dcda6" - optionalDependencies: - "@types/geojson" "^1.0.0" - test-exclude@^4.2.1: version "4.2.3" resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-4.2.3.tgz#a9a5e64474e4398339245a0a769ad7c2f4a97c20" @@ -9385,7 +9413,7 @@ uuid@2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.2.tgz#48bd5698f0677e3c7901a1c46ef15b1643794726" -uuid@3.3.2, uuid@^3.0.0, uuid@^3.2.1, uuid@^3.3.2: +uuid@3.3.2, uuid@^3.2.1, uuid@^3.3.2: version "3.3.2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131" @@ -9400,9 +9428,9 @@ validator@5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/validator/-/validator-5.2.0.tgz#e66fb3ec352348c1f7232512328738d8d66a9689" -validator@^9.1.0: - version "9.4.1" - resolved "https://registry.yarnpkg.com/validator/-/validator-9.4.1.tgz#abf466d398b561cd243050112c6ff1de6cc12663" +validator@^10.11.0: + version "10.11.0" + resolved "https://registry.yarnpkg.com/validator/-/validator-10.11.0.tgz#003108ea6e9a9874d31ccc9e5006856ccd76b228" value-equal@^0.4.0: version "0.4.0" @@ -9644,9 +9672,9 @@ windows-release@^3.1.0: dependencies: execa "^0.10.0" -wkx@^0.4.1: - version "0.4.6" - resolved "https://registry.yarnpkg.com/wkx/-/wkx-0.4.6.tgz#228ab592e6457382ea6fb79fc825058d07fce523" +wkx@^0.4.6: + version "0.4.7" + resolved "https://registry.yarnpkg.com/wkx/-/wkx-0.4.7.tgz#ba0e4f9e785e95c9975856c1834f19a95c65cfb5" dependencies: "@types/node" "*" @@ -9675,6 +9703,14 @@ wrap-ansi@^2.0.0: string-width "^1.0.1" strip-ansi "^3.0.1" +wrap-ansi@^5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-5.1.0.tgz#1fd1f67235d5b6d0fee781056001bfb694c03b09" + dependencies: + ansi-styles "^3.2.0" + string-width "^3.0.0" + strip-ansi "^5.0.0" + wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" @@ -9748,7 +9784,7 @@ y18n@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.1.tgz#6d15fba884c08679c0d77e88e7759e811e07fa41" -"y18n@^3.2.1 || ^4.0.0", y18n@^4.0.0: +y18n@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b" @@ -9760,9 +9796,9 @@ yallist@^3.0.0, yallist@^3.0.2: version "3.0.3" resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.3.tgz#b4b049e314be545e3ce802236d6cd22cd91c3de9" -yargs-parser@^11.1.1: - version "11.1.1" - resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-11.1.1.tgz#879a0865973bca9f6bab5cbdf3b1c67ec7d3bcf4" +yargs-parser@^13.1.0: + version "13.1.1" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.1.tgz#d26058532aa06d365fe091f6a1fc06b2f7e5eca0" dependencies: camelcase "^5.0.0" decamelize "^1.2.0" @@ -9803,22 +9839,21 @@ yargs@^10.0.3: y18n "^3.2.1" yargs-parser "^8.1.0" -yargs@^12.0.5: - version "12.0.5" - resolved "https://registry.yarnpkg.com/yargs/-/yargs-12.0.5.tgz#05f5997b609647b64f66b81e3b4b10a368e7ad13" +yargs@^13.1.0: + version "13.2.4" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.2.4.tgz#0b562b794016eb9651b98bd37acf364aa5d6dc83" dependencies: - cliui "^4.0.0" - decamelize "^1.2.0" + cliui "^5.0.0" find-up "^3.0.0" - get-caller-file "^1.0.1" - os-locale "^3.0.0" + get-caller-file "^2.0.1" + os-locale "^3.1.0" require-directory "^2.1.1" - require-main-filename "^1.0.1" + require-main-filename "^2.0.0" set-blocking "^2.0.0" - string-width "^2.0.0" + string-width "^3.0.0" which-module "^2.0.0" - y18n "^3.2.1 || ^4.0.0" - yargs-parser "^11.1.1" + y18n "^4.0.0" + yargs-parser "^13.1.0" yargs@^4.2.0: version "4.8.1"