-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathinterfaces.ts
130 lines (108 loc) · 3.02 KB
/
interfaces.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
122
123
124
125
126
127
128
129
130
export type Identifier = string | number
export interface IRecord {
id: Identifier
[key: string]: any
}
export interface FormRecord {
[key: string]: any
}
export interface SortPayload {
field: string
order: string
}
export interface FilterPayload {
[k: string]: any
}
export interface PaginationPayload {
page: number
perPage: number
}
export interface PaginationResponse {
current_page: number
per_page: number
total: number
}
export type OptionType = { value: string; label: string }
export type DataProvider = {
getList: <RecordType extends IRecord = IRecord>(
resource: string,
params: Partial<GetListParams>,
) => Promise<GetListResult<RecordType>>
reorderList: (resource: string, params: ReorderParams) => Promise<void>
getOne: <RecordType extends IRecord = IRecord>(
resource: string,
params: GetOneParams,
) => Promise<GetOneResult<RecordType>>
getCreateFormData: <RecordType extends FormRecord = FormRecord>(
resource: string,
) => Promise<GetFormDataResult<RecordType>>
getUpdateFormData: <RecordType extends FormRecord = FormRecord>(
resource: string,
params: GetOneParams,
) => Promise<GetFormDataResult<RecordType>>
getFiltersFormData: (
resource: string,
urlState?: Record<string, any>,
) => Promise<GetFiltersFormDataResult>
update: <RecordType extends IRecord = IRecord>(
resource: string,
params: UpdateParams,
) => Promise<UpdateResult<RecordType>>
create: <RecordType extends IRecord = IRecord>(
resource: string,
params: CreateParams,
) => Promise<CreateResult<RecordType>>
deleteOne: <RecordType extends IRecord = IRecord>(
resource: string,
params: DeleteParams,
) => Promise<DeleteResult<RecordType>>
[key: string]: any
}
export interface GetListParams {
pagination: PaginationPayload
sort: SortPayload
filter: any
}
export interface GetListResult<RecordType extends IRecord = IRecord> {
items: RecordType[]
meta: PaginationResponse
}
export interface ReorderParams<T = any> {
data: T
}
export interface GetOneParams {
id: Identifier
}
export interface RecordOptions {
[k: string]: OptionType[]
}
export interface GetOneResult<RecordType extends IRecord = IRecord> {
data: RecordType
values: RecordOptions
}
export interface GetFormDataResult<RecordType extends FormRecord = FormRecord> {
data: RecordType
values: RecordOptions
}
export interface GetFiltersFormDataResult {
options: RecordOptions
}
export interface UpdateParams<T = any> {
id: Identifier
data: T
}
export interface UpdateResult<RecordType extends IRecord = IRecord> {
data: RecordType
}
export interface CreateParams<T = any> {
data: T
}
export interface CreateResult<RecordType extends IRecord = IRecord> {
data: RecordType
}
export interface DeleteParams {
id: Identifier
}
export interface DeleteResult<RecordType extends IRecord = IRecord> {
data: RecordType
}