-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
types.d.ts
46 lines (39 loc) · 1022 Bytes
/
types.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Knex } from 'knex';
interface IPaginateParams {
perPage: number;
currentPage: number;
isFromStart?: boolean;
isLengthAware?: boolean;
}
interface IWithPagination<Data, TParams = IPaginateParams> {
data: Data[];
pagination: IPagination<TParams>;
}
type IPagination<TParams> = TParams extends
| { currentPage: 1 }
| { isFromStart: true }
| { isLengthAware: true }
? ILengthAwarePagination
: IBasePagination;
interface IBasePagination {
currentPage: number;
perPage: number;
from: number;
to: number;
}
interface ILengthAwarePagination extends IBasePagination {
total: number;
lastPage: number;
prevPage: number;
nextPage: number;
}
declare module 'knex' {
namespace Knex {
interface QueryBuilder<TRecord extends {} = any, TResult = any> {
paginate<TParams extends IPaginateParams = IPaginateParams>(
params: Readonly<TParams>
): Knex.QueryBuilder<TRecord, IWithPagination<TRecord, TParams>>;
}
}
}
export function attachPaginate(): void;