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

chore: export { WhereConditions } #400

Merged
merged 2 commits into from
Oct 31, 2023
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
8 changes: 4 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const eslintConfig = {
'no-const-assign': 'error',
'no-undef': 2,
'no-underscore-dangle': 0,
'no-use-before-define': [2, 'nofunc'],
'no-use-before-define': ['error', {'functions': false, 'classes': false}],
'no-unused-vars': [2, { 'vars': 'all', 'args': 'none', 'ignoreRestSiblings': true }],
'no-shadow': 2,
'keyword-spacing': 'error',
Expand All @@ -42,16 +42,16 @@ const tslintConfig = {
'plugin:@typescript-eslint/recommended',
],
parser: '@typescript-eslint/parser',
files: ['*.ts'],
files: ['**/*.ts'],
plugins: [
'@typescript-eslint',
'no-only-tests',
],
rules: {
...eslintConfig.rules,
'@typescript-eslint/no-var-requires': 0,
'@typescript-eslint/no-use-before-define': ['error'],
strict: 0,
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': ['error', {'functions': false, 'classes': false}],
'@typescript-eslint/ban-ts-comment': ['warn'],
'no-shadow': 'off',
'@typescript-eslint/no-shadow': ['warn'],
Expand Down
20 changes: 10 additions & 10 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import DataTypes, { DataType, AbstractDataType, LENGTH_VARIANTS } from './src/data_types';
import {
import {
Hint, IndexHint, HintInterface,
INDEX_HINT_SCOPE_TYPE, INDEX_HINT_SCOPE, INDEX_HINT_TYPE
} from './src/hint';
import {
Literal, Validator,
Connection, QueryOptions,
Connection, QueryOptions, WhereConditions,
Raw, ColumnMeta, AttributeMeta,
BeforeHooksType, AfterHooksType, Collection,
GeneratorReturnType, Values, BoneCreateValues, BoneInstanceValues,
Expand All @@ -14,9 +14,9 @@ import { SpellMeta, Spell, SpellBookFormatResult } from './src/spell';
import Bone from './src/bone';
import { ConnectOptions, AbstractDriver } from './src/drivers';

export {
export {
LENGTH_VARIANTS as LENGTH_VARIANTS,
DataTypes, Literal, Validator, Connection,
DataTypes, Literal, Validator, Connection, WhereConditions,
Hint, IndexHint, HintInterface, INDEX_HINT_SCOPE_TYPE, INDEX_HINT_SCOPE, INDEX_HINT_TYPE,
Bone, Raw, Collection,
SpellMeta, Spell, ColumnMeta, AttributeMeta, SpellBookFormatResult, Values, BoneCreateValues, BoneInstanceValues,
Expand All @@ -32,7 +32,7 @@ interface InitOptions {
hooks?: {
[key in BeforeHooksType ]: (options: QueryOptions) => Promise<void>
} | {
[key in AfterHooksType ]: (instance: Bone, result: Object) => Promise<void>
[key in AfterHooksType ]: (instance: Bone, result: object) => Promise<void>
};
}

Expand Down Expand Up @@ -62,13 +62,13 @@ export default class Realm {
* disconnect manually
* @param callback
*/
disconnect(callback?: Function): Promise<boolean | void>;
disconnect(callback?: () => Promise<void>): Promise<boolean | void>;

define(
name: string,
attributes: Record<string, AbstractDataType<DataType> | AttributeMeta>,
options?: InitOptions,
descriptors?: Record<string, Function>,
descriptors?: Record<string, PropertyDescriptor>,
): typeof Bone;

raw(sql: string): Raw;
Expand All @@ -94,11 +94,11 @@ export default class Realm {
* })
*/
export function connect(opts: ConnectOptions): Promise<Realm>;
export function disconnect(realm: Realm, callback?: Function): Promise<boolean | void>;
export function disconnect(realm: Realm, callback?: () => Promise<void>): Promise<boolean | void>;

/**
* Check if cls is subclass of Bone
* @param cls
* @param cls
*/
export function isBone(cls: any): boolean;

Expand All @@ -110,6 +110,6 @@ export function isBone(cls: any): boolean;
* FROM users
* WHERE age >= 35
* `)
* @param text
* @param text
*/
export function heresql(text): string;
18 changes: 6 additions & 12 deletions src/adapters/sequelize.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import {
Attributes, Literal, OperatorCondition,
Attributes, Literal, WhereConditions,
BoneOptions, ResultSet, Raw,
SetOptions, BeforeHooksType, AfterHooksType,
QueryOptions, OrderOptions, QueryResult, Values as CommonValues, BoneColumns, InstanceColumns, BoneCreateValues,
} from '../types/common';
import { AbstractBone } from '../types/abstract_bone';
import { Spell } from '../spell';

type WhereConditions<T extends typeof SequelizeBone> = {
[Property in BoneColumns<T>]?: Literal | Literal[] | OperatorCondition;
} | {
[key in '$and' | '$or']?: WhereConditions<T>[];
}

interface SequelizeDestroyOptions extends QueryOptions {
force?: boolean;
}
Expand Down Expand Up @@ -62,8 +56,8 @@ type aggregators = 'count' | 'COUNT' | 'average' | 'AVERAGE' | 'minimum' | 'MINI

export class Collection<T extends SequelizeBone> extends Array<T> {
save(): Promise<void>;
toJSON(): Object[];
toObject(): Object[];
toJSON(): object[];
toObject(): object[];
}

export class SequelizeBone extends AbstractBone {
Expand All @@ -85,10 +79,10 @@ export class SequelizeBone extends AbstractBone {
* @param {string | Function} fnNameOrFun function name or function
* @param {Function} func hook function
*/
static addHook(
static addHook<T extends SequelizeBone>(
name: BeforeHooksType | AfterHooksType | 'beforeDestroy' | 'afterDestroy' | 'beforeBulkDestroy' | 'afterBulkDestroy' | 'beforeBulkUpdate' | 'afterBulkUpdate',
fnNameOrFun: string | Function,
func?: Function,
fnNameOrFun: string | ((target: T, ...args: [Record<keyof Extract<CommonValues<T>, Literal>, Literal>, ...any[]]) => void),
func?: (target: T, ...args: [Record<keyof Extract<CommonValues<T>, Literal>, Literal>, ...any[]]) => void,
): void;

/**
Expand Down
10 changes: 6 additions & 4 deletions src/spell.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import {
Literal, command, Raw, Connection,
ResultSet, QueryResult,
QueryOptions, SetOptions, WithOptions,
Expand Down Expand Up @@ -54,6 +54,8 @@ interface ExprTernaryOperator {
type ExprOperator = ExprBinaryOperator | ExprTernaryOperator;
type SpellColumn = ExprIdentifier | Raw;

type ScopeFunction = (spell: SpellMeta) => void;

interface SpellOptions {
command?: command;
columns: SpellColumn[];
Expand All @@ -64,7 +66,7 @@ interface SpellOptions {
havingCondtions: ExprOperator[];
joins: Join;
skip: number;
scopes: Function[];
scopes: ScopeFunction[];
subqueryIndex: number;
rowCount?: number;
connection?: Connection;
Expand Down Expand Up @@ -96,7 +98,7 @@ export class Spell<T extends typeof AbstractBone, U = InstanceType<T> | Collecti
connection: Connection;

command: string;
scopes: Function[];
scopes: Array<(spell: this) => void>;

select(...names: Array<string | Raw> | Array<(name: string) => boolean>): Spell<T, U>;
insert(opts: SetOptions<T>): Spell<T, QueryResult>;
Expand Down Expand Up @@ -136,7 +138,7 @@ export class Spell<T extends typeof AbstractBone, U = InstanceType<T> | Collecti

$offset(skip: number): Spell<T, U>;
offset(skip: number): Spell<T, U>;

$limit(rowCount: number): Spell<T, U>;
limit(rowCount: number): Spell<T, U>;

Expand Down
Loading
Loading