Skip to content

Make IFindOptions generic #162

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

Merged
merged 1 commit into from
Oct 11, 2017
Merged
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
2 changes: 1 addition & 1 deletion lib/interfaces/IFindCreateFindOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IFindOptions} from "./IFindOptions";

export interface IFindCreateFindOptions<TAttributes> extends IFindOptions {
export interface IFindCreateFindOptions<TAttributes> extends IFindOptions<TAttributes> {

/**
* Default values to use if building a new instance
Expand Down
6 changes: 3 additions & 3 deletions lib/interfaces/IFindOptions.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {WhereOptions, LoggingOptions, SearchPathOptions, col, and, or, FindOptionsAttributesArray,
import {WhereOptions, LoggingOptions, SearchPathOptions, col, FindOptionsAttributesArray,
literal, fn} from 'sequelize';
import {Model} from "../models/Model";
import {IIncludeOptions} from "./IIncludeOptions";

/* tslint:disable:array-type */
/* tslint:disable:max-line-length */

export interface IFindOptions extends LoggingOptions, SearchPathOptions {
export interface IFindOptions<T> extends LoggingOptions, SearchPathOptions {

/**
* A hash of attributes to describe your search. See above for examples.
*/
where?: WhereOptions<any> | Array<col | and | or | string> | col | and | or | string;
where?: WhereOptions<T>;

/**
* A list of the attributes that you want to select. To rename an attribute, you can pass an array, with
Expand Down
2 changes: 1 addition & 1 deletion lib/interfaces/IFindOrInitializeOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IFindOptions} from "./IFindOptions";

export interface IFindOrInitializeOptions<TAttributes> extends IFindOptions {
export interface IFindOrInitializeOptions<TAttributes> extends IFindOptions<TAttributes> {

/**
* Default values to use if building a new instance
Expand Down
2 changes: 1 addition & 1 deletion lib/models/BaseModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export abstract class BaseModel {
*
* SEE DETAILS FOR ACTUAL FUNCTIONALITY ON DECLARATION FILE
*/
reload(options?: IFindOptions): Promise<this> {
reload(options?: IFindOptions<typeof BaseModel>): Promise<this> {

return parentPrototype.reload.call(this, inferAlias(options, this));
};
Expand Down
18 changes: 9 additions & 9 deletions lib/models/Model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export declare abstract class Model<T> extends Hooks {
* @param {Object} [options]
* @param {Boolean} [options.override=false]
*/
static addScope(name: string, scope: IFindOptions | Function, options?: AddScopeOptions): void;
static addScope<T extends Model<T>>(name: string, scope: IFindOptions<T> | Function, options?: AddScopeOptions): void;

/**
* Apply a scope created in `define` to the model. First let's look at how to create scopes:
Expand Down Expand Up @@ -194,25 +194,25 @@ export declare abstract class Model<T> extends Hooks {
*
* @see {Sequelize#query}
*/
static findAll<T extends Model<T>>(options?: IFindOptions): Promise<T[]>;
static findAll<T extends Model<T>>(options?: IFindOptions<T>): Promise<T[]>;

static all<T extends Model<T>>(optionz?: IFindOptions): Promise<T[]>;
static all<T extends Model<T>>(options?: IFindOptions<T>): Promise<T[]>;

/**
* 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<T extends Model<T>>(identifier?: number | string, options?: IFindOptions): Promise<T | null>;
static findById<T extends Model<T>>(identifier?: number | string, options?: IFindOptions<T>): Promise<T | null>;

static findByPrimary<T extends Model<T>>(identifier?: number | string, options?: IFindOptions): Promise<T | null>;
static findByPrimary<T extends Model<T>>(identifier?: number | string, options?: IFindOptions<T>): Promise<T | null>;

/**
* Search for a single instance. This applies LIMIT 1, so the listener will always be called with a single
* instance.
*/
static findOne<T extends Model<T>>(options?: IFindOptions): Promise<T | null>;
static findOne<T extends Model<T>>(options?: IFindOptions<T>): Promise<T | null>;

static find<T extends Model<T>>(options?: IFindOptions): Promise<T | null>;
static find<T extends Model<T>>(options?: IFindOptions<T>): Promise<T | null>;

/**
* Run an aggregation method on the specified field
Expand Down Expand Up @@ -267,9 +267,9 @@ export declare abstract class Model<T> extends Hooks {
* without
* profiles will be counted
*/
static findAndCount<T extends Model<T>>(options?: IFindOptions): Promise<{rows: T[], count: number}>;
static findAndCount<T extends Model<T>>(options?: IFindOptions<T>): Promise<{rows: T[], count: number}>;

static findAndCountAll<T extends Model<T>>(options?: IFindOptions): Promise<{rows: T[], count: number}>;
static findAndCountAll<T extends Model<T>>(options?: IFindOptions<T>): Promise<{rows: T[], count: number}>;

/**
* Find the maximum value of field
Expand Down
2 changes: 1 addition & 1 deletion lib/services/scopes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function resolveScope(scopeName: string, model: typeof Model, options: IScopeFin
} else {
options = inferAlias(options, model);
}
model.addScope(scopeName, options as IFindOptions, {override: true});
model.addScope(scopeName, options as IFindOptions<typeof Model>, {override: true});
}

/**
Expand Down