Fix linting errors

This commit is contained in:
keenondrums
2018-06-24 18:14:06 -06:00
parent 6d6bea5b12
commit 2ca6a7806b
3 changed files with 148 additions and 150 deletions
+142 -144
View File
@@ -1,217 +1,215 @@
// Type definitions for redux-orm 0.9.4
// Type definitions for redux-orm 0.9
// Project: https://github.com/tommikaikkonen/redux-orm#readme
// Definitions by: Andrey Goncharov <https://github.com/keenondrums>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
interface IORMId {
id: string
export interface ORMId {
id: string;
}
interface ITableState<Item = any, Meta = any> {
items: string[],
itemsById: { [index: string]: Item },
meta: Meta
export interface TableState<Item = any, Meta = any> {
items: string[];
itemsById: { [index: string]: Item };
meta: Meta;
}
interface IORMCommonState {
[index: string]: ITableState
export interface ORMCommonState {
[index: string]: TableState;
}
type ISession<State extends IORMCommonState> = Session<State> & { [P in keyof State]: typeof Model }
export type SessionWithModels<State extends ORMCommonState> = Session<State> & { [P in keyof State]: typeof Model };
type IModel<Fields, Additional = {}, VirtualFields = {}> = Model<Fields, Additional, VirtualFields> & Fields & VirtualFields & Additional & IORMId
export type ModelWithFields<Fields, Additional = {}, VirtualFields = {}> = Model<Fields, Additional, VirtualFields> & Fields & VirtualFields & Additional & ORMId;
// TODO: Refine me
type IModelProps = any
export type ModelProps = any;
// TODO: Refine me
interface IDB {
getEmptyState: any,
query: any,
update: any,
describe: any
export interface DB {
getEmptyState: any;
query: any;
update: any;
describe: any;
}
// TODO: Refine me
interface ISchemaSpec {
tables: any
export interface SchemaSpec {
tables: any;
}
// TODO: Refine me
interface IORMOpts {
createDatabase: (schemaSpec: ISchemaSpec) => any
export interface ORMOpts {
createDatabase: (schemaSpec: SchemaSpec) => any;
}
interface IModelFields {
[index: string]: Attribute | ForeignKey | ManyToMany | OneToOne
export interface ModelFields {
[index: string]: Attribute | ForeignKey | ManyToMany | OneToOne;
}
interface IModelVirtualFields {
[index: string]: any
export interface ModelVirtualFields {
[index: string]: any;
}
export class ORM<State extends IORMCommonState = IORMCommonState> {
constructor(opts?: IORMOpts)
register(...model: Array<typeof Model>): void
register<M>(...model: Array<M[keyof M]>): void
registerManyToManyModelsFor(model: typeof Model): void
get(modelName: string): typeof Model
getModelClasses(): Array<typeof Model>
isFieldInstalled(modelName: string, fieldName: string): boolean
setFieldInstalled(modelName: string, fieldName: string): void
generateSchemaSpec(): ISchemaSpec
getDatabase(): IDB
getEmptyState(): State
session(state: State): ISession<State>
mutableSession(state: State): ISession<State>
export class ORM<State extends ORMCommonState = ORMCommonState> {
constructor(opts?: ORMOpts)
register(...model: Array<typeof Model>): void;
register<M>(...model: Array<M[keyof M]>): void;
registerManyToManyModelsFor(model: typeof Model): void;
get(modelName: string): typeof Model;
getModelClasses(): Array<typeof Model>;
isFieldInstalled(modelName: string, fieldName: string): boolean;
setFieldInstalled(modelName: string, fieldName: string): void;
generateSchemaSpec(): SchemaSpec;
getDatabase(): DB;
getEmptyState(): State;
session(state: State): SessionWithModels<State>;
mutableSession(state: State): SessionWithModels<State>;
private _attachQuerySetMethods(model: typeof Model): void
private _setupModelPrototypes(models: Array<typeof Model>): void
private _attachQuerySetMethods(model: typeof Model): void;
private _setupModelPrototypes(models: Array<typeof Model>): void;
}
export class Model<Fields, Additional = {}, VirtualFields = {}> {
static readonly idAttribute: string
static readonly session: ISession<any>
static readonly _sessionData: any // TODO
static readonly query: QuerySet<any>
static readonly idAttribute: string;
static readonly session: SessionWithModels<any>;
static readonly _sessionData: any; // TODO
static readonly query: QuerySet<any>;
static modelName: string
static fields: IModelFields
static virtualFields: IModelVirtualFields
static querySetClass: typeof QuerySet
static modelName: string;
static fields: ModelFields;
static virtualFields: ModelVirtualFields;
static querySetClass: typeof QuerySet;
static toString(): string
static options<T = object>(): T
static _getTableOpts<T = object>(): T
static markAccessed(): void
static connect<State extends IORMCommonState>(session: Session<State>): void
static getQuerySet<T extends QuerySet<any> = QuerySet<any>>(): T
static invalidateClassCache(): void
static all<Fields, Additional = {}, VirtualFields = {}>(): QuerySet<Fields, Additional, VirtualFields>
static create<Fields, Additional = {}, VirtualFields = {}>(props: Fields): IModel<Fields, Additional, VirtualFields>
static upsert<Fields, Additional = {}, VirtualFields = {}>(props: Partial<Fields>): IModel<Fields, Additional, VirtualFields>
static withId<Fields, Additional = {}, VirtualFields = {}>(id: string): IModel<Fields, Additional, VirtualFields>
static hasId(id: string): boolean
static _findDatabaseRows(lookupObj: object): any // TODO
static get<Fields, Additional = {}, VirtualFields = {}>(lookupObj: Object): IModel<Fields, Additional, VirtualFields>
static reducer<State extends IORMCommonState>(session: ISession<State>, action: any): any
static toString(): string;
static options(): object;
static _getTableOpts(): object;
static markAccessed(): void;
static connec(session: Session<ORMCommonState>): void;
static getQuerySet(): QuerySet<any>;
static invalidateClassCache(): void;
static all(): QuerySet<any, any, any>;
static create<Fields>(props: Fields): ModelWithFields<Fields, any, any>;
static upsert<Fields>(props: Partial<Fields>): ModelWithFields<Fields, any, any>;
static withId(id: string): ModelWithFields<any, any, any>;
static hasId(id: string): boolean;
static _findDatabaseRows(lookupObj: object): any; // TODO
static get(lookupObj: object): ModelWithFields<any, any, any>;
static reducer(session: SessionWithModels<ORMCommonState>, action: any): any;
readonly ref: Fields & Additional & IORMId
readonly ref: Fields & Additional & ORMId;
constructor(props: IModelProps)
constructor(props: ModelProps)
getClass(): string
getId(): string
toString(): string
equals<OtherFields, OtherAdditional = {}, OtherVirtualFields = {}>(otherModel: IModel<OtherFields, OtherAdditional, OtherVirtualFields>): boolean
set<T = any>(propertyName: string, value: T): void
update(userMergeObj: Partial<Fields & Additional>): void
refreshFromState(): void
delete(): void
getClass(): string;
getId(): string;
toString(): string;
equals(otherModel: ModelWithFields<any, any, any>): boolean;
set(propertyName: string, value: any): void;
update(userMergeObj: Partial<Fields & Additional>): void;
refreshFromState(): void;
delete(): void;
private _onDelete(): void
private _initFields(props: IModelProps): void
private _refreshMany2Many(relations: any): void //TODO
private _onDelete(): void;
private _initFields(props: ModelProps): void;
private _refreshMany2Many(relations: any): void; // TODO
}
type IQuerySetClauses = any // TODO
type IQuerySetOpts = any // TODO
declare class QuerySet<Fields, Additional = {}, VirtualFields = {}> {
static addSharedMethod(methodName: string): void
export type QuerySetClauses = any; // TODO
export type QuerySetOpts = any; // TODO
export class QuerySet<Fields, Additional = {}, VirtualFields = {}> {
static addSharedMethod(methodName: string): void;
constructor(modelClass: typeof Model, clauses: IQuerySetClauses, opts: IQuerySetOpts)
constructor(modelClass: typeof Model, clauses: QuerySetClauses, opts: QuerySetOpts)
toString(): string
toRefArray(): Array<Fields & Additional & IORMId>
toModelArray(): Array<IModel<Fields, Additional, VirtualFields>>
count(): number
exists(): boolean
at(index: string): IModel<Fields, Additional, VirtualFields> | undefined
first(): IModel<Fields, Additional, VirtualFields> | undefined
last(): IModel<Fields, Additional, VirtualFields> | undefined
all(): QuerySet<Fields, Additional, VirtualFields>
filter(lookupObj: object): QuerySet<Fields, Additional, VirtualFields> // TODO
exclude(lookupObj: object): QuerySet<Fields, Additional, VirtualFields> // TODO
orderBy(iteratees: any, orders: any): QuerySet<Fields, Additional, VirtualFields> // TODO
update(mergeObj: Partial<Fields & Additional>): void
delete(): void
toString(): string;
toRefArray(): Array<Fields & Additional & ORMId>;
toModelArray(): Array<ModelWithFields<Fields, Additional, VirtualFields>>;
count(): number;
exists(): boolean;
at(index: string): ModelWithFields<Fields, Additional, VirtualFields> | undefined;
first(): ModelWithFields<Fields, Additional, VirtualFields> | undefined;
last(): ModelWithFields<Fields, Additional, VirtualFields> | undefined;
all(): QuerySet<Fields, Additional, VirtualFields>;
filter(lookupObj: object): QuerySet<Fields, Additional, VirtualFields>; // TODO
exclude(lookupObj: object): QuerySet<Fields, Additional, VirtualFields>; // TODO
orderBy(iteratees: any, orders: any): QuerySet<Fields, Additional, VirtualFields>; // TODO
update(mergeObj: Partial<Fields & Additional>): void;
delete(): void;
private _evaluate(): void
private _new(clauses: IQuerySetClauses, userOpts: IQuerySetOpts): QuerySet<Fields, Additional, VirtualFields>
private _evaluate(): void;
private _new(clauses: QuerySetClauses, userOpts: QuerySetOpts): QuerySet<Fields, Additional, VirtualFields>;
}
export class Session<State extends IORMCommonState> {
readonly accessedModels: string[]
schema: ORM<State>
db: IDB
initialState: State
withMutations: boolean
batchToken: any
sessionBoundModels: Array<typeof Model>
models: Array<typeof Model>
state: State
export class Session<State extends ORMCommonState> {
readonly accessedModels: string[];
schema: ORM<State>;
db: DB;
initialState: State;
withMutations: boolean;
batchToken: any;
sessionBoundModels: Array<typeof Model>;
models: Array<typeof Model>;
state: State;
constructor(schema: ORM<State>, db: IDB, state: State, withMutations: boolean, batchToken: any) // TODO
markAccessed(modelName: string): void
getDataForModel(modelName: string): object
applyUpdate(updateSpec: any): any // TODO
query(querySpec: any): any // TODO
constructor(schema: ORM<State>, db: DB, state: State, withMutations: boolean, batchToken: any) // TODO
markAccessed(modelName: string): void;
getDataForModel(modelName: string): object;
applyUpdate(updateSpec: any): any; // TODO
query(querySpec: any): any; // TODO
}
interface IAttributeOpts {
getDefault?: () => any
export interface AttributeOpts {
getDefault?: () => any;
}
export class Attribute {
constructor (opts: IAttributeOpts)
install(model: typeof Model, fieldName: string, orm: ORM): void
constructor(opts: AttributeOpts)
install(model: typeof Model, fieldName: string, orm: ORM): void;
}
interface IRelationalFieldOpts {
to: string,
relatedName?: string,
through?: string,
export interface RelationalFieldOpts {
to: string;
relatedName?: string;
through?: string;
throughFields?: {
to: string,
from: string
}
to: string;
from: string;
};
}
export class RelationalField {
constructor (toModelName: string, relatedName?: string)
constructor (opts: IRelationalFieldOpts)
getClass: typeof RelationalField
constructor(toModelName: string, relatedName?: string)
constructor(opts: RelationalFieldOpts)
getClass: typeof RelationalField;
}
export class ForeignKey extends RelationalField {
install(model: typeof Model, fieldName: string, orm: ORM): void
install(model: typeof Model, fieldName: string, orm: ORM): void;
}
export class ManyToMany extends RelationalField {
install(model: typeof Model, fieldName: string, orm: ORM): void
install(model: typeof Model, fieldName: string, orm: ORM): void;
}
export class OneToOne extends RelationalField {
install(model: typeof Model, fieldName: string, orm: ORM): void
install(model: typeof Model, fieldName: string, orm: ORM): void;
}
export function attr(opts?: IAttributeOpts): Attribute
export function attr(opts?: AttributeOpts): Attribute;
export function fk(toModelName: string, relatedName?: string): ForeignKey
export function fk(opts: IRelationalFieldOpts): ForeignKey
export function fk(toModelName: string, relatedName?: string): ForeignKey;
export function fk(opts: RelationalFieldOpts): ForeignKey;
export function many(toModelName: string, relatedName?: string): ManyToMany;
export function oneToOne(toModelName: string, relatedName?: string): OneToOne;
export function oneToOne(opts: RelationalFieldOpts): OneToOne;
export function many(toModelName: string, relatedName?: string): ManyToMany
export function many(opts: IRelationalFieldOpts): ManyToMany
export type Updater<State extends ORMCommonState> = (session: SessionWithModels<State>, action: any) => any;
export function oneToOne(toModelName: string, relatedName?: string): OneToOne
export function oneToOne(opts: IRelationalFieldOpts): OneToOne
export function createReducer<State extends ORMCommonState = ORMCommonState>(orm: ORM<State>, updater?: Updater<State>): (state: State, action: any) => State;
type IUpdater<State extends IORMCommonState> = (session: ISession<State>, action: any) => any
export type ORMSelector<State extends ORMCommonState, Result = any> = (session: SessionWithModels<State>, ...args: any[]) => Result;
export function createReducer<State extends IORMCommonState = IORMCommonState>(orm: ORM<State>, updater?: IUpdater<State>): (state: State, action: any) => State
type IORMSelector<State extends IORMCommonState, Result = any> = (session: ISession<State>, ...args: any[]) => Result
export function createSelector<State extends IORMCommonState = IORMCommonState, Result = any>(orm: ORM<State>, ...args: IORMSelector<State>[]): (state: State) => Result
export function createSelector<State extends ORMCommonState = ORMCommonState>(orm: ORM<State>, ...args: Array<ORMSelector<State>>): (state: State) => any;
+5 -6
View File
@@ -1,4 +1,4 @@
import { attr, createSelector as createSelectorORM, IORMCommonState, IORMId, ITableState, ISession, Model, ORM } from 'redux-orm';
import { attr, createSelector as createSelectorORM, ORMCommonState, ORMId, QuerySet, TableState, SessionWithModels, Model, ORM } from 'redux-orm';
// Model
export class Test extends Model<TestStateItem, FetchIndicatorState> {
@@ -22,9 +22,9 @@ export interface FetchIndicatorState {
}
// id attr is added automatically by redux-orm therefore we have IORMId interface
export type TestState = ITableState<TestStateItem & IORMId & FetchIndicatorState>;
export type TestState = TableState<TestStateItem & ORMId & FetchIndicatorState>;
export interface TestORMState extends IORMCommonState {
export interface TestORMState extends ORMCommonState {
Test: TestState;
}
@@ -66,9 +66,8 @@ interface RootState {
}
export const makeGetTestDisplayList = () => {
const ormSelector = createSelectorORM<TestORMState>(orm, (session: ISession<TestORMState>) =>
session.Test
.all<TestStateItem, FetchIndicatorState>()
const ormSelector = createSelectorORM<TestORMState>(orm, (session: SessionWithModels<TestORMState>) =>
(session.Test.all() as QuerySet<TestStateItem, FetchIndicatorState>)
.toRefArray()
.map((item) => ({ ...item }))
);
+1
View File
@@ -7,6 +7,7 @@
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"