Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapped types v3 #85

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6,078 changes: 18 additions & 6,060 deletions 3/index.d.ts

Large diffs are not rendered by default.

125 changes: 125 additions & 0 deletions 3/lib/associations/base.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@

import {Model} from '../model';
import {Instance} from '../instance';
import {ColumnOptions} from '../sequelize';

export abstract class Association<TSourceModel extends Model<Instance>, TTargetModel extends Model<Instance>> {
associationType: string;
source: TSourceModel;
target: TTargetModel;
isSelfAssociation: boolean;
isSingleAssociation: boolean;
isMultiAssociation: boolean;
as: string;
isAliased: boolean;
foreignKey: string;
identifier: string;
toInstanceArray(objs: any): Instance[];
inspect(): string;
}

export interface SingleAssociationAccessors {
get: string;
set: string;
create: string;
}

export interface MultiAssociationAccessors {
get: string;
set: string;
addMultiple: string;
add: string;
create: string;
remove: string;
removeMultiple: string;
hasSingle: string;
hasAll: string;
count: string;
}

/** Foreign Key Options */
export interface ForeignKeyOptions extends ColumnOptions<any> {

/** Attribute name for the relation */
name?: string;
}


/**
* Options provided when associating models
*/
export interface 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 | ForeignKeyOptions;

/**
* 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
*/
export interface AssociationScope {

/**
* The name of the column that will be used for the associated scope and it's value
*/
[scopeName: string]: any;
}

/**
* Options provided for many-to-many relationships
*/
export interface ManyToManyOptions extends 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;
}
Loading