@finema/core 1.1.5 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -11
- package/dist/module.cjs +5 -0
- package/dist/module.d.mts +15 -0
- package/dist/module.d.ts +15 -0
- package/dist/module.json +8 -0
- package/dist/module.mjs +28 -0
- package/dist/runtime/composables/useLibs.d.ts +24 -0
- package/dist/runtime/composables/useLibs.mjs +4 -0
- package/dist/runtime/composables/useUtils.d.ts +10 -0
- package/dist/runtime/composables/useUtils.mjs +12 -0
- package/dist/{lib → runtime/lib}/Requester.d.ts +1 -1
- package/dist/runtime/lib/Requester.mjs +37 -0
- package/dist/{lib → runtime/lib}/api/apiListHelper.d.ts +2 -2
- package/dist/runtime/lib/api/apiListHelper.mjs +44 -0
- package/dist/{lib → runtime/lib}/api/apiObjectHelper.d.ts +2 -2
- package/dist/runtime/lib/api/apiObjectHelper.mjs +46 -0
- package/dist/{lib → runtime/lib}/api/apiPageHelper.d.ts +2 -2
- package/dist/runtime/lib/api/apiPageHelper.mjs +265 -0
- package/dist/runtime/lib/api/config.mjs +4 -0
- package/dist/{lib → runtime/lib}/api/loaderList.d.ts +1 -1
- package/dist/runtime/lib/api/loaderList.mjs +49 -0
- package/dist/{lib → runtime/lib}/api/loaderObject.d.ts +1 -1
- package/dist/runtime/lib/api/loaderObject.mjs +50 -0
- package/dist/{lib → runtime/lib}/api/loaderPage.d.ts +1 -1
- package/dist/runtime/lib/api/loaderPage.mjs +219 -0
- package/dist/{lib → runtime/lib}/api/loaderTypes.d.ts +3 -3
- package/dist/runtime/lib/api/loaderTypes.mjs +0 -0
- package/dist/{lib → runtime/lib}/index.d.ts +0 -2
- package/dist/runtime/lib/index.mjs +8 -0
- package/dist/runtime/plugin.d.ts +2 -0
- package/dist/runtime/plugin.mjs +4 -0
- package/dist/runtime/types/common.d.ts +13 -0
- package/dist/runtime/types/lib.d.ts +102 -0
- package/dist/runtime/utils/FileHelper.mjs +29 -0
- package/dist/{utils → runtime/utils}/ObjectHelper.d.ts +3 -3
- package/dist/runtime/utils/ObjectHelper.mjs +108 -0
- package/dist/{utils → runtime/utils}/ParamHelper.d.ts +2 -1
- package/dist/runtime/utils/ParamHelper.mjs +39 -0
- package/dist/runtime/utils/StringHelper.mjs +41 -0
- package/dist/runtime/utils/TimeHelper.mjs +83 -0
- package/dist/runtime/utils/lodash.mjs +38 -0
- package/dist/types.d.mts +15 -0
- package/dist/types.d.ts +15 -0
- package/package.json +64 -31
- package/dist/composables/index.d.ts +0 -1
- package/dist/composables/useCookie.d.ts +0 -5
- package/dist/composables/useWatch.d.ts +0 -3
- package/dist/core.js +0 -10031
- package/dist/core.umd.cjs +0 -49
- package/dist/index.d.ts +0 -3
- package/dist/lib/api/types.d.ts +0 -89
- package/dist/lib/api/utils.d.ts +0 -9
- package/dist/utils/ArrayHelper.d.ts +0 -7
- package/dist/utils/ArrayHelper.spec.d.ts +0 -1
- package/dist/utils/CookieHelper.d.ts +0 -9
- package/dist/utils/ObjectHelper.spec.d.ts +0 -1
- package/dist/utils/ParamHelper.spec.d.ts +0 -1
- package/dist/utils/StringHelper.spec.d.ts +0 -1
- package/dist/utils/TimeHelper.spec.d.ts +0 -1
- package/dist/utils/faker.d.ts +0 -2
- package/dist/utils/index.d.ts +0 -9
- package/dist/utils/types.d.ts +0 -8
- /package/dist/{lib → runtime/lib}/api/config.d.ts +0 -0
- /package/dist/{utils → runtime/utils}/FileHelper.d.ts +0 -0
- /package/dist/{utils → runtime/utils}/StringHelper.d.ts +0 -0
- /package/dist/{utils → runtime/utils}/TimeHelper.d.ts +0 -0
- /package/dist/{utils → runtime/utils}/lodash.d.ts +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IListLoaderOptions, IUseListLoader } from './loaderTypes';
|
|
1
|
+
import { type IListLoaderOptions, type IUseListLoader } from './loaderTypes';
|
|
2
2
|
export declare const useListLoader: <T = any, O = Record<string, any>>(loaderOptions: IListLoaderOptions<T, O>) => IUseListLoader<T, O>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
import { ObjectHelper } from "../../utils/ObjectHelper.mjs";
|
|
3
|
+
import { apiListHelper } from "./apiListHelper.mjs";
|
|
4
|
+
export const useListLoader = (loaderOptions) => {
|
|
5
|
+
const status = ref(ObjectHelper.createStatus());
|
|
6
|
+
const items = ref([]);
|
|
7
|
+
const options = ref({});
|
|
8
|
+
const clear = () => {
|
|
9
|
+
status.value = ObjectHelper.createStatus();
|
|
10
|
+
items.value = [];
|
|
11
|
+
};
|
|
12
|
+
const run = async (opts) => {
|
|
13
|
+
return apiListHelper(
|
|
14
|
+
() => ({
|
|
15
|
+
status: status.value,
|
|
16
|
+
items: items.value,
|
|
17
|
+
options: options.value
|
|
18
|
+
}),
|
|
19
|
+
(_data) => {
|
|
20
|
+
status.value = _data;
|
|
21
|
+
},
|
|
22
|
+
(_data) => {
|
|
23
|
+
options.value = _data;
|
|
24
|
+
},
|
|
25
|
+
(_data) => {
|
|
26
|
+
items.value = _data;
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
...loaderOptions,
|
|
30
|
+
...opts
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
const setLoading = () => {
|
|
35
|
+
status.value = ObjectHelper.toLoadingStatus(status.value);
|
|
36
|
+
};
|
|
37
|
+
const setItems = (_items) => {
|
|
38
|
+
items.value = _items;
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
items,
|
|
42
|
+
status,
|
|
43
|
+
options,
|
|
44
|
+
run,
|
|
45
|
+
clear,
|
|
46
|
+
setItems,
|
|
47
|
+
setLoading
|
|
48
|
+
};
|
|
49
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IObjectLoaderOptions, IUseObjectLoader } from './loaderTypes';
|
|
1
|
+
import { type IObjectLoaderOptions, type IUseObjectLoader } from './loaderTypes';
|
|
2
2
|
export declare const useObjectLoader: <T = any, B = any, O = Record<string, any>>(loaderOptions: IObjectLoaderOptions<T, B, O>) => IUseObjectLoader<T, B, O>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
import { ObjectHelper } from "../../utils/ObjectHelper.mjs";
|
|
3
|
+
import { apiObjectHelper } from "./apiObjectHelper.mjs";
|
|
4
|
+
export const useObjectLoader = (loaderOptions) => {
|
|
5
|
+
const status = ref(ObjectHelper.createStatus());
|
|
6
|
+
const data = ref(null);
|
|
7
|
+
const options = ref({});
|
|
8
|
+
const clear = () => {
|
|
9
|
+
status.value = ObjectHelper.createStatus();
|
|
10
|
+
data.value = null;
|
|
11
|
+
};
|
|
12
|
+
const run = async (payload, opts = {}) => {
|
|
13
|
+
await apiObjectHelper(
|
|
14
|
+
() => ({
|
|
15
|
+
status: status.value,
|
|
16
|
+
data: data.value,
|
|
17
|
+
options: options.value
|
|
18
|
+
}),
|
|
19
|
+
(_data) => {
|
|
20
|
+
status.value = _data;
|
|
21
|
+
},
|
|
22
|
+
(_data) => {
|
|
23
|
+
options.value = _data;
|
|
24
|
+
},
|
|
25
|
+
(_data) => {
|
|
26
|
+
data.value = _data;
|
|
27
|
+
},
|
|
28
|
+
payload,
|
|
29
|
+
{
|
|
30
|
+
...loaderOptions,
|
|
31
|
+
...opts
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
const setLoading = () => {
|
|
36
|
+
status.value = ObjectHelper.toLoadingStatus(status.value);
|
|
37
|
+
};
|
|
38
|
+
const setData = (_data) => {
|
|
39
|
+
data.value = _data;
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
data,
|
|
43
|
+
status,
|
|
44
|
+
options,
|
|
45
|
+
run,
|
|
46
|
+
clear,
|
|
47
|
+
setLoading,
|
|
48
|
+
setData
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
import { ObjectHelper } from "../../utils/ObjectHelper.mjs";
|
|
3
|
+
import {
|
|
4
|
+
apiAddHelper,
|
|
5
|
+
apiDeleteHelper,
|
|
6
|
+
apiFetchHelper,
|
|
7
|
+
apiFindHelper,
|
|
8
|
+
updateHelper
|
|
9
|
+
} from "./apiPageHelper.mjs";
|
|
10
|
+
import { CONFIG } from "./config.mjs";
|
|
11
|
+
export const initPageOptions = () => ({
|
|
12
|
+
currentPageCount: 0,
|
|
13
|
+
currentPage: 1,
|
|
14
|
+
totalPage: 0,
|
|
15
|
+
totalCount: 0,
|
|
16
|
+
limit: CONFIG.LIMIT_PER_PAGE,
|
|
17
|
+
search: "",
|
|
18
|
+
primary: CONFIG.DEFAULT_PRIMARY
|
|
19
|
+
});
|
|
20
|
+
export const usePageLoader = (loaderOptions) => {
|
|
21
|
+
const fetchStatus = ref(ObjectHelper.createStatus());
|
|
22
|
+
const fetchItems = ref([]);
|
|
23
|
+
const findItem = ref(null);
|
|
24
|
+
const deleteItem = ref(null);
|
|
25
|
+
const addItem = ref(null);
|
|
26
|
+
const updateItem = ref(null);
|
|
27
|
+
const findStatus = ref(ObjectHelper.createStatus());
|
|
28
|
+
const addStatus = ref(ObjectHelper.createStatus());
|
|
29
|
+
const updateStatus = ref(ObjectHelper.createStatus());
|
|
30
|
+
const deleteStatus = ref(ObjectHelper.createStatus());
|
|
31
|
+
const fetchOptions = ref(initPageOptions());
|
|
32
|
+
const addOptions = ref({});
|
|
33
|
+
const findOptions = ref({});
|
|
34
|
+
const updateOptions = ref({});
|
|
35
|
+
const deleteOptions = ref({});
|
|
36
|
+
const clear = () => {
|
|
37
|
+
findStatus.value = ObjectHelper.createStatus();
|
|
38
|
+
deleteStatus.value = ObjectHelper.createStatus();
|
|
39
|
+
addStatus.value = ObjectHelper.createStatus();
|
|
40
|
+
updateStatus.value = ObjectHelper.createStatus();
|
|
41
|
+
findItem.value = null;
|
|
42
|
+
deleteItem.value = null;
|
|
43
|
+
updateItem.value = null;
|
|
44
|
+
fetchStatus.value = ObjectHelper.createStatus();
|
|
45
|
+
fetchOptions.value = initPageOptions();
|
|
46
|
+
findOptions.value = {};
|
|
47
|
+
addOptions.value = {};
|
|
48
|
+
deleteOptions.value = {};
|
|
49
|
+
fetchItems.value = [];
|
|
50
|
+
};
|
|
51
|
+
const setFetchLoading = () => {
|
|
52
|
+
fetchStatus.value = ObjectHelper.toLoadingStatus(fetchStatus.value);
|
|
53
|
+
};
|
|
54
|
+
const setFindLoading = () => {
|
|
55
|
+
findStatus.value = ObjectHelper.toLoadingStatus(findStatus.value);
|
|
56
|
+
};
|
|
57
|
+
const fetch = async (page = 1, query = "", opts) => {
|
|
58
|
+
await apiFetchHelper(
|
|
59
|
+
() => ({
|
|
60
|
+
status: fetchStatus.value,
|
|
61
|
+
items: fetchItems.value,
|
|
62
|
+
options: fetchOptions.value
|
|
63
|
+
}),
|
|
64
|
+
(data) => {
|
|
65
|
+
fetchStatus.value = data;
|
|
66
|
+
},
|
|
67
|
+
(data) => {
|
|
68
|
+
fetchOptions.value = data;
|
|
69
|
+
},
|
|
70
|
+
(data) => {
|
|
71
|
+
fetchItems.value = data;
|
|
72
|
+
},
|
|
73
|
+
page,
|
|
74
|
+
query,
|
|
75
|
+
{
|
|
76
|
+
...loaderOptions,
|
|
77
|
+
...opts
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
const find = async (id, opts) => {
|
|
82
|
+
await apiFindHelper(
|
|
83
|
+
() => ({
|
|
84
|
+
status: findStatus.value,
|
|
85
|
+
data: findItem.value,
|
|
86
|
+
options: findOptions.value
|
|
87
|
+
}),
|
|
88
|
+
(data) => {
|
|
89
|
+
findStatus.value = data;
|
|
90
|
+
},
|
|
91
|
+
(data) => {
|
|
92
|
+
findOptions.value = data;
|
|
93
|
+
},
|
|
94
|
+
(data) => {
|
|
95
|
+
findItem.value = data;
|
|
96
|
+
},
|
|
97
|
+
id,
|
|
98
|
+
{
|
|
99
|
+
...loaderOptions,
|
|
100
|
+
...opts
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
const add = async (data, opts) => {
|
|
105
|
+
await apiAddHelper(
|
|
106
|
+
() => ({
|
|
107
|
+
items: fetchItems.value,
|
|
108
|
+
status: addStatus.value,
|
|
109
|
+
data: addItem.value,
|
|
110
|
+
options: addOptions.value
|
|
111
|
+
}),
|
|
112
|
+
(data2) => {
|
|
113
|
+
addStatus.value = data2;
|
|
114
|
+
},
|
|
115
|
+
(data2) => {
|
|
116
|
+
addOptions.value = data2;
|
|
117
|
+
},
|
|
118
|
+
(data2) => {
|
|
119
|
+
addItem.value = data2;
|
|
120
|
+
},
|
|
121
|
+
(data2) => {
|
|
122
|
+
fetchItems.value = data2;
|
|
123
|
+
},
|
|
124
|
+
data,
|
|
125
|
+
{
|
|
126
|
+
...loaderOptions,
|
|
127
|
+
...opts
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
const update = async (id, data, opts) => {
|
|
132
|
+
await updateHelper(
|
|
133
|
+
() => ({
|
|
134
|
+
items: fetchItems.value,
|
|
135
|
+
status: updateStatus.value,
|
|
136
|
+
data: updateItem.value,
|
|
137
|
+
oldData: findItem.value,
|
|
138
|
+
options: updateOptions.value
|
|
139
|
+
}),
|
|
140
|
+
(data2) => {
|
|
141
|
+
updateStatus.value = data2;
|
|
142
|
+
},
|
|
143
|
+
(data2) => {
|
|
144
|
+
updateOptions.value = data2;
|
|
145
|
+
},
|
|
146
|
+
(data2) => {
|
|
147
|
+
updateItem.value = data2;
|
|
148
|
+
},
|
|
149
|
+
(data2) => {
|
|
150
|
+
fetchItems.value = data2;
|
|
151
|
+
},
|
|
152
|
+
(data2) => {
|
|
153
|
+
findItem.value = data2;
|
|
154
|
+
},
|
|
155
|
+
id,
|
|
156
|
+
data,
|
|
157
|
+
{
|
|
158
|
+
...loaderOptions,
|
|
159
|
+
...opts
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
};
|
|
163
|
+
const search = async (query = "", opts) => {
|
|
164
|
+
await fetch(1, query, opts);
|
|
165
|
+
};
|
|
166
|
+
const remove = async (id, opts) => {
|
|
167
|
+
await apiDeleteHelper(
|
|
168
|
+
() => ({
|
|
169
|
+
status: deleteStatus.value,
|
|
170
|
+
data: deleteItem.value,
|
|
171
|
+
items: fetchItems.value,
|
|
172
|
+
options: deleteOptions.value
|
|
173
|
+
}),
|
|
174
|
+
(data) => {
|
|
175
|
+
deleteStatus.value = data;
|
|
176
|
+
},
|
|
177
|
+
(data) => {
|
|
178
|
+
deleteOptions.value = data;
|
|
179
|
+
},
|
|
180
|
+
(data) => {
|
|
181
|
+
deleteItem.value = data;
|
|
182
|
+
},
|
|
183
|
+
(data) => {
|
|
184
|
+
fetchItems.value = data;
|
|
185
|
+
},
|
|
186
|
+
id,
|
|
187
|
+
{
|
|
188
|
+
...loaderOptions,
|
|
189
|
+
...opts
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
fetchItems,
|
|
195
|
+
fetchOptions,
|
|
196
|
+
addOptions,
|
|
197
|
+
findOptions,
|
|
198
|
+
deleteOptions,
|
|
199
|
+
updateOptions,
|
|
200
|
+
fetchStatus,
|
|
201
|
+
deleteStatus,
|
|
202
|
+
deleteItem,
|
|
203
|
+
fetch,
|
|
204
|
+
search,
|
|
205
|
+
remove,
|
|
206
|
+
find,
|
|
207
|
+
findItem,
|
|
208
|
+
findStatus,
|
|
209
|
+
add,
|
|
210
|
+
addItem,
|
|
211
|
+
addStatus,
|
|
212
|
+
updateItem,
|
|
213
|
+
updateStatus,
|
|
214
|
+
update,
|
|
215
|
+
setFetchLoading,
|
|
216
|
+
setFindLoading,
|
|
217
|
+
clear
|
|
218
|
+
};
|
|
219
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AxiosRequestConfig, Method } from 'axios';
|
|
2
|
-
import { Ref, UnwrapRef } from 'vue';
|
|
3
|
-
import { IAPIOptions, IPageOptions, IStatus } from '
|
|
1
|
+
import { type AxiosRequestConfig, type Method } from 'axios';
|
|
2
|
+
import { type Ref, type UnwrapRef } from 'vue';
|
|
3
|
+
import { type IAPIOptions, type IPageOptions, type IStatus } from '../../types/lib';
|
|
4
4
|
export interface IPageFetchLoaderOptions<D = Record<string, any>> {
|
|
5
5
|
isMock?: boolean;
|
|
6
6
|
params?: Record<string, any>;
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./Requester.mjs";
|
|
2
|
+
export * from "./api/apiListHelper.mjs";
|
|
3
|
+
export * from "./api/apiObjectHelper.mjs";
|
|
4
|
+
export * from "./api/apiPageHelper.mjs";
|
|
5
|
+
export * from "./api/loaderList.mjs";
|
|
6
|
+
export * from "./api/loaderObject.mjs";
|
|
7
|
+
export * from "./api/loaderPage.mjs";
|
|
8
|
+
export * from "./api/loaderTypes.mjs";
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { type AxiosRequestConfig } from 'axios'
|
|
2
|
+
|
|
3
|
+
export interface IAPIOptions {
|
|
4
|
+
_status?: number
|
|
5
|
+
_timestamp?: number
|
|
6
|
+
request?: Partial<AxiosRequestConfig>
|
|
7
|
+
[key: string]: any
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface IPageOptions extends IAPIOptions {
|
|
11
|
+
currentPageCount: number
|
|
12
|
+
currentPage: number
|
|
13
|
+
totalPage: number
|
|
14
|
+
totalCount: number
|
|
15
|
+
limit: number
|
|
16
|
+
search?: string
|
|
17
|
+
primary?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface IStatus {
|
|
21
|
+
isError: boolean
|
|
22
|
+
isSuccess: boolean
|
|
23
|
+
isLoading: boolean
|
|
24
|
+
isLoaded: boolean
|
|
25
|
+
errorData: any | null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface IAPIFetchState<T> {
|
|
29
|
+
items: T[]
|
|
30
|
+
status: IStatus
|
|
31
|
+
options: IPageOptions
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface IAPIFindState<T> {
|
|
35
|
+
data: T
|
|
36
|
+
status: IStatus
|
|
37
|
+
options: IAPIOptions
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface IAPIAddState<T> {
|
|
41
|
+
data: T
|
|
42
|
+
items: T[]
|
|
43
|
+
status: IStatus
|
|
44
|
+
options: IAPIOptions
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface IAPIObjectState<T> {
|
|
48
|
+
data: T | null
|
|
49
|
+
status: IStatus
|
|
50
|
+
options: IAPIOptions
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface IAPIListState<T> {
|
|
54
|
+
items: T[]
|
|
55
|
+
status: IStatus
|
|
56
|
+
options: IAPIOptions
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface IAPIDeleteState<T> {
|
|
60
|
+
data: T
|
|
61
|
+
items: T[]
|
|
62
|
+
status: IStatus
|
|
63
|
+
options: IAPIOptions
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface IAPIUpdateState<T> {
|
|
67
|
+
data: T
|
|
68
|
+
oldData: T
|
|
69
|
+
items: T[] | undefined | null
|
|
70
|
+
status: IStatus
|
|
71
|
+
options: IAPIOptions
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface IPageState<T> {
|
|
75
|
+
deleteStatus: IStatus
|
|
76
|
+
updateStatus: IStatus
|
|
77
|
+
addStatus: IStatus
|
|
78
|
+
findStatus: IStatus
|
|
79
|
+
fetchStatus: IStatus
|
|
80
|
+
fetchItems: T[]
|
|
81
|
+
findItem: null | T
|
|
82
|
+
addItem: null | T
|
|
83
|
+
updateItem: null | T
|
|
84
|
+
deleteItem: null | T | any
|
|
85
|
+
findOptions: object
|
|
86
|
+
addOptions: object
|
|
87
|
+
deleteOptions: object
|
|
88
|
+
updateOptions: object
|
|
89
|
+
fetchOptions: IPageOptions
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface IObjectState<T> {
|
|
93
|
+
data: T | null
|
|
94
|
+
status: IStatus
|
|
95
|
+
options: IAPIOptions
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface IListState<T> {
|
|
99
|
+
items: T[]
|
|
100
|
+
status: IStatus
|
|
101
|
+
options: IAPIOptions
|
|
102
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export class FileHelper {
|
|
2
|
+
static toBase64 = async (file) => {
|
|
3
|
+
return new Promise((resolve, reject) => {
|
|
4
|
+
const reader = new FileReader();
|
|
5
|
+
reader.readAsDataURL(file);
|
|
6
|
+
reader.onload = () => {
|
|
7
|
+
resolve(reader.result);
|
|
8
|
+
};
|
|
9
|
+
reader.onerror = (error) => {
|
|
10
|
+
reject(error);
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
static readFileAsync = async (file) => {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const reader = new FileReader();
|
|
17
|
+
reader.onload = (ev) => {
|
|
18
|
+
resolve(ev.target ? ev.target.result : "");
|
|
19
|
+
};
|
|
20
|
+
reader.onerror = reject;
|
|
21
|
+
reader.readAsText(file);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
static dataURLtoFile = async (dataUrl, filename) => {
|
|
25
|
+
const res = await fetch(dataUrl);
|
|
26
|
+
const blob = await res.blob();
|
|
27
|
+
return new File([blob], filename, { type: "image/png" });
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AxiosError } from 'axios';
|
|
2
|
-
import { IStatus } from '../lib';
|
|
3
|
-
import { IOption } from '
|
|
1
|
+
import { type AxiosError } from 'axios';
|
|
2
|
+
import { type IStatus } from '../types/lib';
|
|
3
|
+
import { type IOption } from '../types/common';
|
|
4
4
|
export declare class ObjectHelper {
|
|
5
5
|
static createOption(value: any, label?: string): IOption;
|
|
6
6
|
static toOption(data: any, valueAttr?: string, labelAttr?: string): IOption;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { _get, _isEmpty } from "./lodash.mjs";
|
|
2
|
+
import { ParamHelper } from "./ParamHelper.mjs";
|
|
3
|
+
export class ObjectHelper {
|
|
4
|
+
static createOption(value, label = "") {
|
|
5
|
+
return {
|
|
6
|
+
value,
|
|
7
|
+
label
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
static toOption(data, valueAttr = "id", labelAttr = "name") {
|
|
11
|
+
const newData = data || {};
|
|
12
|
+
const value = _get(newData, valueAttr, "");
|
|
13
|
+
return {
|
|
14
|
+
value,
|
|
15
|
+
label: _get(newData, labelAttr, value)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
static toOptions(data, valueAttr = "id", labelAttr = "name") {
|
|
19
|
+
if (!data) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
const value = _get(data, valueAttr, "");
|
|
23
|
+
return [
|
|
24
|
+
{
|
|
25
|
+
value,
|
|
26
|
+
label: _get(data, labelAttr, value)
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
static toStatus(obj) {
|
|
31
|
+
return {
|
|
32
|
+
isLoaded: ParamHelper.getBoolFalse(obj.isLoaded),
|
|
33
|
+
isLoading: ParamHelper.getBoolFalse(obj.isLoading),
|
|
34
|
+
isError: ParamHelper.getBoolFalse(obj.isError),
|
|
35
|
+
isSuccess: ParamHelper.getBoolFalse(obj.isSuccess),
|
|
36
|
+
errorData: obj.errorData || null
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
static toLoadingStatus(obj) {
|
|
40
|
+
return {
|
|
41
|
+
...obj,
|
|
42
|
+
isLoaded: false,
|
|
43
|
+
isError: false,
|
|
44
|
+
isLoading: true,
|
|
45
|
+
isSuccess: false
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
static toItemsSuccessStatus(obj, items) {
|
|
49
|
+
return {
|
|
50
|
+
...obj,
|
|
51
|
+
isSuccess: true,
|
|
52
|
+
errorData: null,
|
|
53
|
+
items
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
static toObjectSuccessStatus(obj, data = null) {
|
|
57
|
+
return {
|
|
58
|
+
...obj,
|
|
59
|
+
isSuccess: true,
|
|
60
|
+
errorData: null,
|
|
61
|
+
data
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
static toErrorStatus(obj, error) {
|
|
65
|
+
let newError = JSON.parse(error.response?.request?.response || "{}");
|
|
66
|
+
if (!error.response?.status) {
|
|
67
|
+
newError = {
|
|
68
|
+
code: "NETWORK_ERROR",
|
|
69
|
+
message: "Network error"
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
...obj,
|
|
74
|
+
isError: true,
|
|
75
|
+
isSuccess: false,
|
|
76
|
+
errorData: newError
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
static toSuccessStatus(obj) {
|
|
80
|
+
return {
|
|
81
|
+
...obj,
|
|
82
|
+
isSuccess: true,
|
|
83
|
+
errorData: null
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
static toCompleteStatus(obj) {
|
|
87
|
+
return {
|
|
88
|
+
...obj,
|
|
89
|
+
isLoading: false,
|
|
90
|
+
isLoaded: true
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
static createStatus() {
|
|
94
|
+
return {
|
|
95
|
+
isLoaded: false,
|
|
96
|
+
isLoading: false,
|
|
97
|
+
isError: false,
|
|
98
|
+
isSuccess: false,
|
|
99
|
+
errorData: null
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
static isInvalidParams(errorData) {
|
|
103
|
+
return errorData.code === "INVALID_PARAMS";
|
|
104
|
+
}
|
|
105
|
+
static isEmpty = (object) => {
|
|
106
|
+
return _isEmpty(object);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { IError } from '
|
|
1
|
+
import { type IError, type IGetParams } from '../types/common';
|
|
2
2
|
export declare class ParamHelper {
|
|
3
|
+
static getParams: (opts: IGetParams, reqOptions: IGetParams) => Record<string, any> | undefined;
|
|
3
4
|
static getBoolTrue: (bool: any) => boolean;
|
|
4
5
|
static getBoolFalse: (bool: any) => boolean;
|
|
5
6
|
static isNotFoundError: (error: IError | any) => boolean;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { _get } from "./lodash.mjs";
|
|
2
|
+
export class ParamHelper {
|
|
3
|
+
static getParams = (opts, reqOptions) => {
|
|
4
|
+
if (opts.params) {
|
|
5
|
+
return {
|
|
6
|
+
...reqOptions.params,
|
|
7
|
+
...opts.params
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
return reqOptions.params;
|
|
11
|
+
};
|
|
12
|
+
static getBoolTrue = (bool) => {
|
|
13
|
+
if (bool === "false") {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (bool === "true") {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return bool === null ? true : !!bool;
|
|
20
|
+
};
|
|
21
|
+
static getBoolFalse = (bool) => {
|
|
22
|
+
if (bool === "false") {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (bool === "true") {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return bool === null ? false : !!bool;
|
|
29
|
+
};
|
|
30
|
+
static isNotFoundError = (error) => {
|
|
31
|
+
return _get(error, "code", true) === "NOT_FOUND";
|
|
32
|
+
};
|
|
33
|
+
static isChangeWithFalse = (value, oldValue) => {
|
|
34
|
+
return oldValue !== value && !value;
|
|
35
|
+
};
|
|
36
|
+
static isChangeWithTrue = (value, oldValue) => {
|
|
37
|
+
return oldValue !== value && value;
|
|
38
|
+
};
|
|
39
|
+
}
|