-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
121 lines (97 loc) · 2.83 KB
/
types.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import type {NextFunction, Request, Response, Router} from 'express';
import type {
Attributes,
CreateOptions,
DestroyOptions,
FindAndCountOptions,
FindOptions,
Model,
ModelCtor,
NonNullFindOptions,
UpdateOptions,
} from 'sequelize';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type modelType = ModelCtor<Model<any, any>> | string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type pureModelType = ModelCtor<Model<any, any>>;
export type expressFunc = (
req: Request,
res: Response,
next: NextFunction
) => void;
export type sequelizeFunc<T> = (req: Request, res: Response) => Promise<T> | T;
export type sequelizePropOrFunc<T> = T extends unknown
? T | sequelizeFunc<T>
: never;
export type expressCrudProps<T> = {
[key in keyof T]: sequelizePropOrFunc<T[key]>;
};
type customFieldCore = {include: string[]} | {exclude: string[]} | string[];
export type customFields = sequelizePropOrFunc<customFieldCore>;
interface operationFieldCore {
middleware?: expressFunc;
}
interface getListCore {
filterableFields?: customFields;
sortableFields?: customFields;
}
interface getListOptionsWithPagination
extends operationFieldCore,
getListCore,
expressCrudProps<Omit<FindAndCountOptions<unknown>, 'group' | 'offset'>> {
pagination: true;
}
interface getListOptionsWithOutPagination
extends operationFieldCore,
getListCore,
expressCrudProps<FindOptions<unknown>> {
pagination?: false;
}
export type getListOptions =
| getListOptionsWithPagination
| getListOptionsWithOutPagination;
export interface getOneOptions
extends operationFieldCore,
expressCrudProps<
Omit<NonNullFindOptions<Attributes<Model>>, 'where' | 'rejectOnEmpty'>
> {
byField?: string;
}
export interface createOptions
extends operationFieldCore,
expressCrudProps<Omit<CreateOptions<unknown>, 'transaction'>> {
creatableFields?: customFields;
}
export interface updateOptions
extends operationFieldCore,
expressCrudProps<Omit<UpdateOptions<unknown>, 'where' | 'transaction'>> {
updatableFields?: customFields;
}
export interface deleteOptions
extends operationFieldCore,
expressCrudProps<Omit<DestroyOptions<unknown>, 'where' | 'transaction'>> {}
type customRoutesFunc = (router: Router) => void;
type operationsType = {
getList?: getListOptions;
getOne?: getOneOptions;
create?: createOptions;
update?: updateOptions;
delete?: deleteOptions;
custom?: customRoutesFunc;
};
export type sequelizeCrudConfigModel = {
model: modelType;
operations: operationsType;
};
export type sequelizeCrudConfig = {
[basepath: string]: sequelizeCrudConfigModel;
};
type logFunc = (msg: unknown) => void;
export type LoggerOptions = {
info: logFunc;
warn: logFunc;
error: logFunc;
};
export type sequelizeCrudOptions = {
logging?: LoggerOptions;
};