Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
D-Sketon committed Nov 4, 2023
1 parent 546f482 commit 2cb780e
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Schema from './schema';
import SchemaType from './schematype';
import WarehouseError from './error';
import { logger } from 'hexo-log';
import type { NodeJSLikeCallback } from './types';

const log = logger();
const pkg = require('../package.json');
Expand Down
1 change: 1 addition & 0 deletions src/document.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import rfdc from 'rfdc';
import type Model from './model';
import type Schema from './schema';
import type { NodeJSLikeCallback } from './types';
const cloneDeep = rfdc();

abstract class Document {
Expand Down
1 change: 1 addition & 0 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import WarehouseError from './error';
import PopulationError from './error/population';
import Mutex from './mutex';
import type Database from './database';
import type { NodeJSLikeCallback, Options } from './types';

class Model extends EventEmitter {
_mutex = new Mutex();
Expand Down
1 change: 1 addition & 0 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { parseArgs, shuffle } from './util';
import type Model from './model';
import type Schema from './schema';
import type Document from './document';
import type { NodeJSLikeCallback, Options } from './types';

abstract class Query {
data: any[];
Expand Down
10 changes: 5 additions & 5 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getProp, setProp, delProp } from './util';
import PopulationError from './error/population';
import SchemaTypeVirtual from './types/virtual';
import { isPlainObject } from 'is-plain-object';
import type { NodeJSLikeCallback } from './types';

/**
* @callback queryFilterCallback
Expand Down Expand Up @@ -57,8 +58,7 @@ const checkHookType = (type: string) => {
}
};

const hookWrapper = (fn: (callback: NodeJSLikeCallback<any>, options?: Promise.PromisifyOptions) => void)
: (callback?: NodeJSLikeCallback<any, any>) => Promise<any> => {
const hookWrapper = (fn: (...args: any[]) => void): (...args: any[]) => Promise<any> => {
if (fn.length > 1) {
return Promise.promisify(fn);
}
Expand All @@ -73,7 +73,7 @@ const execSortStack = (stack: ((a: unknown, b: unknown) => number)[]) => {
const len = stack.length;

return (a: any, b: any) => {
let result;
let result: number;

for (let i = 0; i < len; i++) {
result = stack[i](a, b);
Expand Down Expand Up @@ -567,7 +567,7 @@ class Schema {
* @param {String} type Hook type. One of `save` or `remove`.
* @param {Function} fn
*/
pre(type: string, fn: (callback: NodeJSLikeCallback<any, any>, options?: Promise.PromisifyOptions) => void): void {
pre(type: string, fn: (...args: any[]) => void): void {
checkHookType(type);
if (typeof fn !== 'function') throw new TypeError('Hook must be a function!');

Expand All @@ -580,7 +580,7 @@ class Schema {
* @param {String} type Hook type. One of `save` or `remove`.
* @param {Function} fn
*/
post(type: string, fn: (callback: NodeJSLikeCallback<any, any>, options?: Promise.PromisifyOptions) => void): void {
post(type: string, fn: (...args: any[]) => void): void {
checkHookType(type);
if (typeof fn !== 'function') throw new TypeError('Hook must be a function!');

Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type NodeJSLikeCallback<R, E = any> = (err: E, result?: R) => void
export type NodeJSLikeCallback<R, E = any> = (err: E, result?: R) => void

interface Options {
export interface Options {
lean?: boolean;
skip?: number;
limit?: number;
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ describe('Model', () => {
});
});

it('removeById() - id not exist', () => (User.removeById('foo', {}) as any).should.eventually.be.rejected);
it('removeById() - id not exist', () => (User.removeById('foo', () => {}) as any).should.eventually.be.rejected);

it('removeById() - hook', () => {
const db = new Database();
Expand Down

0 comments on commit 2cb780e

Please sign in to comment.