@finema/core 3.17.2 → 3.19.0
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/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/components/FlexDeck/index.vue +79 -79
- package/dist/runtime/components/Form/FieldWrapper.vue +13 -13
- package/dist/runtime/components/Form/Fields.vue +13 -13
- package/dist/runtime/components/Form/InputCheckbox/index.d.vue.ts +5 -1
- package/dist/runtime/components/Form/InputCheckbox/index.vue +18 -18
- package/dist/runtime/components/Form/InputCheckbox/index.vue.d.ts +5 -1
- package/dist/runtime/components/Form/InputCheckboxGroup/index.d.vue.ts +5 -1
- package/dist/runtime/components/Form/InputCheckboxGroup/index.vue +21 -21
- package/dist/runtime/components/Form/InputCheckboxGroup/index.vue.d.ts +5 -1
- package/dist/runtime/components/Form/InputCurrency/index.d.vue.ts +5 -1
- package/dist/runtime/components/Form/InputCurrency/index.vue +49 -49
- package/dist/runtime/components/Form/InputCurrency/index.vue.d.ts +5 -1
- package/dist/runtime/components/Form/InputDateTime/index.d.vue.ts +5 -1
- package/dist/runtime/components/Form/InputDateTime/index.vue +63 -63
- package/dist/runtime/components/Form/InputDateTime/index.vue.d.ts +5 -1
- package/dist/runtime/components/Form/InputDateTimeRange/index.d.vue.ts +5 -1
- package/dist/runtime/components/Form/InputDateTimeRange/index.vue +56 -56
- package/dist/runtime/components/Form/InputDateTimeRange/index.vue.d.ts +5 -1
- package/dist/runtime/components/Form/InputMonth/index.d.vue.ts +5 -1
- package/dist/runtime/components/Form/InputMonth/index.vue.d.ts +5 -1
- package/dist/runtime/components/Form/InputNumber/index.d.vue.ts +5 -1
- package/dist/runtime/components/Form/InputNumber/index.vue +20 -20
- package/dist/runtime/components/Form/InputNumber/index.vue.d.ts +5 -1
- package/dist/runtime/components/Form/InputSearch/index.d.vue.ts +9 -1
- package/dist/runtime/components/Form/InputSearch/index.vue.d.ts +9 -1
- package/dist/runtime/components/Form/InputSelect/index.d.vue.ts +7 -1
- package/dist/runtime/components/Form/InputSelect/index.vue +110 -110
- package/dist/runtime/components/Form/InputSelect/index.vue.d.ts +7 -1
- package/dist/runtime/components/Form/InputSelectMultiple/index.d.vue.ts +7 -1
- package/dist/runtime/components/Form/InputSelectMultiple/index.vue +118 -118
- package/dist/runtime/components/Form/InputSelectMultiple/index.vue.d.ts +7 -1
- package/dist/runtime/components/Form/InputTags/index.d.vue.ts +11 -1
- package/dist/runtime/components/Form/InputTags/index.vue +54 -54
- package/dist/runtime/components/Form/InputTags/index.vue.d.ts +11 -1
- package/dist/runtime/components/Form/InputText/index.d.vue.ts +7 -1
- package/dist/runtime/components/Form/InputText/index.vue +85 -85
- package/dist/runtime/components/Form/InputText/index.vue.d.ts +7 -1
- package/dist/runtime/components/Form/InputTextarea/index.d.vue.ts +5 -1
- package/dist/runtime/components/Form/InputTextarea/index.vue +18 -18
- package/dist/runtime/components/Form/InputTextarea/index.vue.d.ts +5 -1
- package/dist/runtime/components/Form/InputTime/index.d.vue.ts +5 -1
- package/dist/runtime/components/Form/InputTime/index.vue +38 -38
- package/dist/runtime/components/Form/InputTime/index.vue.d.ts +5 -1
- package/dist/runtime/components/Form/InputToggle/index.d.vue.ts +5 -1
- package/dist/runtime/components/Form/InputToggle/index.vue +17 -17
- package/dist/runtime/components/Form/InputToggle/index.vue.d.ts +5 -1
- package/dist/runtime/components/Form/InputUploadDropzone/index.vue +30 -30
- package/dist/runtime/components/Form/InputUploadDropzoneAuto/index.vue +50 -50
- package/dist/runtime/components/Form/InputUploadDropzoneAutoMultiple/index.vue +50 -50
- package/dist/runtime/components/Form/InputUploadImageAuto/index.vue +50 -50
- package/dist/runtime/components/Form/InputWYSIWYG/EditorImageUploadNode.vue +18 -18
- package/dist/runtime/components/Form/InputWYSIWYG/EditorLinkPopover.vue +65 -65
- package/dist/runtime/components/Form/InputWYSIWYG/README.md +96 -96
- package/dist/runtime/components/Form/InputWYSIWYG/index.vue +41 -41
- package/dist/runtime/components/Form/fileState/EmptyState.vue +21 -21
- package/dist/runtime/components/Form/fileState/FailedState.vue +33 -33
- package/dist/runtime/components/Form/fileState/LoadingState.vue +24 -24
- package/dist/runtime/components/Form/fileState/MultipleFilesState.vue +75 -75
- package/dist/runtime/components/Form/fileState/PreviewModal.vue +23 -23
- package/dist/runtime/components/Form/index.vue +5 -5
- package/dist/runtime/components/Image.vue +28 -28
- package/dist/runtime/components/Log/index.vue +17 -17
- package/dist/runtime/components/Table/Base.d.vue.ts +8 -2
- package/dist/runtime/components/Table/Base.vue +117 -117
- package/dist/runtime/components/Table/Base.vue.d.ts +8 -2
- package/dist/runtime/components/Table/ColumnDate.vue +1 -1
- package/dist/runtime/components/Table/ColumnDateTime.vue +1 -1
- package/dist/runtime/components/Table/ColumnImage.vue +4 -4
- package/dist/runtime/components/Table/ColumnText.vue +10 -10
- package/dist/runtime/components/Table/Pagination.vue +62 -62
- package/dist/runtime/components/Table/Simple.vue +19 -19
- package/dist/runtime/components/Table/index.vue +33 -33
- package/dist/runtime/composables/loaderList.js +38 -15
- package/dist/runtime/composables/loaderObject.js +49 -20
- package/dist/runtime/composables/loaderPage.js +300 -168
- package/dist/runtime/helpers/apiBaseHelper.d.ts +5 -2
- package/dist/runtime/helpers/apiBaseHelper.js +53 -3
- package/dist/runtime/helpers/apiCancelHelper.d.ts +6 -0
- package/dist/runtime/helpers/apiCancelHelper.js +22 -0
- package/dist/runtime/helpers/apiListHelper.js +6 -3
- package/dist/runtime/helpers/apiObjectHelper.d.ts +3 -1
- package/dist/runtime/helpers/apiObjectHelper.js +6 -3
- package/dist/runtime/helpers/apiPageHelper.d.ts +9 -3
- package/dist/runtime/helpers/apiPageHelper.js +29 -16
- package/dist/runtime/server/tsconfig.json +3 -3
- package/package.json +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { reactive } from "vue";
|
|
2
2
|
import { ObjectHelper } from "../utils/ObjectHelper.js";
|
|
3
|
+
import { createCancelableRequest } from "../helpers/apiCancelHelper.js";
|
|
3
4
|
import {
|
|
4
5
|
apiAddHelper,
|
|
5
6
|
apiDeleteHelper,
|
|
@@ -49,7 +50,88 @@ export const usePageLoader = (loaderOptions) => {
|
|
|
49
50
|
item: null,
|
|
50
51
|
options: {}
|
|
51
52
|
});
|
|
53
|
+
const requests = {
|
|
54
|
+
fetch: null,
|
|
55
|
+
find: null,
|
|
56
|
+
add: null,
|
|
57
|
+
update: null,
|
|
58
|
+
delete: null
|
|
59
|
+
};
|
|
60
|
+
const isActiveRequest = (key, currentRequest) => {
|
|
61
|
+
return requests[key] === currentRequest;
|
|
62
|
+
};
|
|
63
|
+
const canUpdateRequest = (key, currentRequest) => {
|
|
64
|
+
return isActiveRequest(key, currentRequest) || !currentRequest.signal.aborted;
|
|
65
|
+
};
|
|
66
|
+
const completeStatus = (status) => ObjectHelper.toCompleteStatus(status);
|
|
67
|
+
const cancelFetch = () => {
|
|
68
|
+
const currentRequest = requests.fetch;
|
|
69
|
+
if (!currentRequest) return;
|
|
70
|
+
currentRequest.controller.abort();
|
|
71
|
+
currentRequest.cleanup();
|
|
72
|
+
requests.fetch = null;
|
|
73
|
+
fetch.status = completeStatus(fetch.status);
|
|
74
|
+
fetch.statusNextPage = completeStatus(fetch.statusNextPage);
|
|
75
|
+
};
|
|
76
|
+
const cancelFind = () => {
|
|
77
|
+
const currentRequest = requests.find;
|
|
78
|
+
if (!currentRequest) return;
|
|
79
|
+
currentRequest.controller.abort();
|
|
80
|
+
currentRequest.cleanup();
|
|
81
|
+
requests.find = null;
|
|
82
|
+
find.status = completeStatus(find.status);
|
|
83
|
+
};
|
|
84
|
+
const cancelAdd = () => {
|
|
85
|
+
const currentRequest = requests.add;
|
|
86
|
+
if (!currentRequest) return;
|
|
87
|
+
currentRequest.controller.abort();
|
|
88
|
+
currentRequest.cleanup();
|
|
89
|
+
requests.add = null;
|
|
90
|
+
add.status = completeStatus(add.status);
|
|
91
|
+
};
|
|
92
|
+
const cancelUpdate = () => {
|
|
93
|
+
const currentRequest = requests.update;
|
|
94
|
+
if (!currentRequest) return;
|
|
95
|
+
currentRequest.controller.abort();
|
|
96
|
+
currentRequest.cleanup();
|
|
97
|
+
requests.update = null;
|
|
98
|
+
update.status = completeStatus(update.status);
|
|
99
|
+
};
|
|
100
|
+
const cancelDelete = () => {
|
|
101
|
+
const currentRequest = requests.delete;
|
|
102
|
+
if (!currentRequest) return;
|
|
103
|
+
currentRequest.controller.abort();
|
|
104
|
+
currentRequest.cleanup();
|
|
105
|
+
requests.delete = null;
|
|
106
|
+
del.status = completeStatus(del.status);
|
|
107
|
+
};
|
|
108
|
+
const cancelAll = () => {
|
|
109
|
+
cancelFetch();
|
|
110
|
+
cancelFind();
|
|
111
|
+
cancelAdd();
|
|
112
|
+
cancelUpdate();
|
|
113
|
+
cancelDelete();
|
|
114
|
+
};
|
|
115
|
+
const cancelRequestByKey = (key) => {
|
|
116
|
+
if (key === "fetch") cancelFetch();
|
|
117
|
+
if (key === "find") cancelFind();
|
|
118
|
+
if (key === "add") cancelAdd();
|
|
119
|
+
if (key === "update") cancelUpdate();
|
|
120
|
+
if (key === "delete") cancelDelete();
|
|
121
|
+
};
|
|
122
|
+
const startRequest = (key, externalSignal, autoCancel = true) => {
|
|
123
|
+
if (autoCancel) cancelRequestByKey(key);
|
|
124
|
+
const currentRequest = createCancelableRequest(externalSignal);
|
|
125
|
+
requests[key] = currentRequest;
|
|
126
|
+
return currentRequest;
|
|
127
|
+
};
|
|
128
|
+
const finishRequest = (key, currentRequest) => {
|
|
129
|
+
currentRequest.cleanup();
|
|
130
|
+
if (!isActiveRequest(key, currentRequest)) return;
|
|
131
|
+
requests[key] = null;
|
|
132
|
+
};
|
|
52
133
|
const clearAll = () => {
|
|
134
|
+
cancelAll();
|
|
53
135
|
find.status = ObjectHelper.createStatus();
|
|
54
136
|
del.status = ObjectHelper.createStatus();
|
|
55
137
|
add.status = ObjectHelper.createStatus();
|
|
@@ -78,138 +160,168 @@ export const usePageLoader = (loaderOptions) => {
|
|
|
78
160
|
find.status = ObjectHelper.toLoadingStatus(find.status);
|
|
79
161
|
};
|
|
80
162
|
const fetchPage = async (page = 1, query = "", opts) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
163
|
+
const currentRequest = startRequest("fetch", opts?.signal);
|
|
164
|
+
try {
|
|
165
|
+
await apiFetchHelper(
|
|
166
|
+
() => ({
|
|
167
|
+
status: fetch.status,
|
|
168
|
+
items: fetch.items,
|
|
169
|
+
options: fetch.options
|
|
170
|
+
}),
|
|
171
|
+
(data) => {
|
|
172
|
+
if (canUpdateRequest("fetch", currentRequest)) fetch.status = data;
|
|
173
|
+
},
|
|
174
|
+
(data) => {
|
|
175
|
+
if (canUpdateRequest("fetch", currentRequest)) fetch.options = data;
|
|
176
|
+
},
|
|
177
|
+
(data) => {
|
|
178
|
+
if (canUpdateRequest("fetch", currentRequest)) fetch.items = data;
|
|
179
|
+
},
|
|
180
|
+
page,
|
|
181
|
+
query,
|
|
182
|
+
{
|
|
183
|
+
...loaderOptions,
|
|
184
|
+
...opts,
|
|
185
|
+
signal: currentRequest.signal
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
} finally {
|
|
189
|
+
finishRequest("fetch", currentRequest);
|
|
190
|
+
}
|
|
103
191
|
};
|
|
104
192
|
const fetchAll = async (query = "", opts = {}) => {
|
|
105
193
|
opts.params = {
|
|
106
194
|
...opts.params,
|
|
107
195
|
limit: 99999
|
|
108
196
|
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
197
|
+
const currentRequest = startRequest("fetch", opts.signal);
|
|
198
|
+
try {
|
|
199
|
+
await apiFetchHelper(
|
|
200
|
+
() => ({
|
|
201
|
+
status: fetch.status,
|
|
202
|
+
items: fetch.items,
|
|
203
|
+
options: fetch.options
|
|
204
|
+
}),
|
|
205
|
+
(data) => {
|
|
206
|
+
if (canUpdateRequest("fetch", currentRequest)) fetch.status = data;
|
|
207
|
+
},
|
|
208
|
+
(data) => {
|
|
209
|
+
if (canUpdateRequest("fetch", currentRequest)) fetch.options = data;
|
|
210
|
+
},
|
|
211
|
+
(data) => {
|
|
212
|
+
if (canUpdateRequest("fetch", currentRequest)) fetch.items = data;
|
|
213
|
+
},
|
|
214
|
+
1,
|
|
215
|
+
query,
|
|
216
|
+
{
|
|
217
|
+
...loaderOptions,
|
|
218
|
+
...opts,
|
|
219
|
+
signal: currentRequest.signal
|
|
220
|
+
}
|
|
221
|
+
);
|
|
222
|
+
} finally {
|
|
223
|
+
finishRequest("fetch", currentRequest);
|
|
224
|
+
}
|
|
131
225
|
};
|
|
132
226
|
const findRun = async (id, opts) => {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
227
|
+
const currentRequest = startRequest("find", opts?.signal);
|
|
228
|
+
try {
|
|
229
|
+
await apiFindHelper(
|
|
230
|
+
() => ({
|
|
231
|
+
status: find.status,
|
|
232
|
+
data: find.item,
|
|
233
|
+
options: find.options
|
|
234
|
+
}),
|
|
235
|
+
(data) => {
|
|
236
|
+
if (canUpdateRequest("find", currentRequest)) find.status = data;
|
|
237
|
+
},
|
|
238
|
+
(data) => {
|
|
239
|
+
if (canUpdateRequest("find", currentRequest)) find.options = data;
|
|
240
|
+
},
|
|
241
|
+
(data) => {
|
|
242
|
+
if (canUpdateRequest("find", currentRequest)) find.item = data;
|
|
243
|
+
},
|
|
244
|
+
id,
|
|
245
|
+
{
|
|
246
|
+
...loaderOptions,
|
|
247
|
+
...opts,
|
|
248
|
+
signal: currentRequest.signal
|
|
249
|
+
}
|
|
250
|
+
);
|
|
251
|
+
} finally {
|
|
252
|
+
finishRequest("find", currentRequest);
|
|
253
|
+
}
|
|
154
254
|
};
|
|
155
255
|
const addRun = async (payload) => {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
256
|
+
const currentRequest = startRequest("add", payload.signal, false);
|
|
257
|
+
try {
|
|
258
|
+
await apiAddHelper(
|
|
259
|
+
() => ({
|
|
260
|
+
items: fetch.items,
|
|
261
|
+
status: add.status,
|
|
262
|
+
data: add.item,
|
|
263
|
+
options: add.options
|
|
264
|
+
}),
|
|
265
|
+
(data) => {
|
|
266
|
+
if (canUpdateRequest("add", currentRequest)) add.status = data;
|
|
267
|
+
},
|
|
268
|
+
(data) => {
|
|
269
|
+
if (canUpdateRequest("add", currentRequest)) add.options = data;
|
|
270
|
+
},
|
|
271
|
+
(data) => {
|
|
272
|
+
if (canUpdateRequest("add", currentRequest)) add.item = data;
|
|
273
|
+
},
|
|
274
|
+
(data) => {
|
|
275
|
+
if (canUpdateRequest("add", currentRequest)) fetch.items = data;
|
|
276
|
+
},
|
|
277
|
+
payload.data,
|
|
278
|
+
{
|
|
279
|
+
...loaderOptions,
|
|
280
|
+
...payload,
|
|
281
|
+
signal: currentRequest.signal
|
|
282
|
+
}
|
|
283
|
+
);
|
|
284
|
+
} finally {
|
|
285
|
+
finishRequest("add", currentRequest);
|
|
286
|
+
}
|
|
181
287
|
};
|
|
182
288
|
const updateRun = async (id, payload) => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
289
|
+
const currentRequest = startRequest("update", payload.signal, false);
|
|
290
|
+
try {
|
|
291
|
+
await updateHelper(
|
|
292
|
+
() => ({
|
|
293
|
+
items: fetch.items,
|
|
294
|
+
status: update.status,
|
|
295
|
+
data: update.item,
|
|
296
|
+
oldData: find.item,
|
|
297
|
+
options: update.options
|
|
298
|
+
}),
|
|
299
|
+
(data) => {
|
|
300
|
+
if (canUpdateRequest("update", currentRequest)) update.status = data;
|
|
301
|
+
},
|
|
302
|
+
(data) => {
|
|
303
|
+
if (canUpdateRequest("update", currentRequest)) update.options = data;
|
|
304
|
+
},
|
|
305
|
+
(data) => {
|
|
306
|
+
if (canUpdateRequest("update", currentRequest)) update.item = data;
|
|
307
|
+
},
|
|
308
|
+
(data) => {
|
|
309
|
+
if (canUpdateRequest("update", currentRequest)) fetch.items = data;
|
|
310
|
+
},
|
|
311
|
+
(data) => {
|
|
312
|
+
if (canUpdateRequest("update", currentRequest)) find.item = data;
|
|
313
|
+
},
|
|
314
|
+
id,
|
|
315
|
+
payload.data,
|
|
316
|
+
{
|
|
317
|
+
...loaderOptions,
|
|
318
|
+
...payload,
|
|
319
|
+
signal: currentRequest.signal
|
|
320
|
+
}
|
|
321
|
+
);
|
|
322
|
+
} finally {
|
|
323
|
+
finishRequest("update", currentRequest);
|
|
324
|
+
}
|
|
213
325
|
};
|
|
214
326
|
const fetchSearch = async (query = "", opts) => {
|
|
215
327
|
await fetchPage(1, query, opts);
|
|
@@ -219,29 +331,37 @@ export const usePageLoader = (loaderOptions) => {
|
|
|
219
331
|
page: _page,
|
|
220
332
|
...params
|
|
221
333
|
} = fetch.options?.request?.params || {};
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
334
|
+
const currentRequest = startRequest("fetch", opts?.signal);
|
|
335
|
+
try {
|
|
336
|
+
await apiFetchHelper(
|
|
337
|
+
() => ({
|
|
338
|
+
status: fetch.status,
|
|
339
|
+
items: fetch.items,
|
|
340
|
+
options: fetch.options
|
|
341
|
+
}),
|
|
342
|
+
(data) => {
|
|
343
|
+
if (canUpdateRequest("fetch", currentRequest)) fetch.statusNextPage = data;
|
|
344
|
+
},
|
|
345
|
+
(data) => {
|
|
346
|
+
if (canUpdateRequest("fetch", currentRequest)) fetch.options = data;
|
|
347
|
+
},
|
|
348
|
+
(data) => {
|
|
349
|
+
if (canUpdateRequest("fetch", currentRequest)) {
|
|
350
|
+
fetch.items = [...fetch.items, ...data];
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
fetch.options.currentPage + 1,
|
|
354
|
+
fetch.options.search || "",
|
|
355
|
+
{
|
|
356
|
+
...loaderOptions,
|
|
357
|
+
params,
|
|
358
|
+
...opts,
|
|
359
|
+
signal: currentRequest.signal
|
|
360
|
+
}
|
|
361
|
+
);
|
|
362
|
+
} finally {
|
|
363
|
+
finishRequest("fetch", currentRequest);
|
|
364
|
+
}
|
|
245
365
|
};
|
|
246
366
|
const fetchPageChange = async (page, opts) => {
|
|
247
367
|
const {
|
|
@@ -254,31 +374,37 @@ export const usePageLoader = (loaderOptions) => {
|
|
|
254
374
|
});
|
|
255
375
|
};
|
|
256
376
|
const deleteRun = async (id, opts) => {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
377
|
+
const currentRequest = startRequest("delete", opts?.signal, false);
|
|
378
|
+
try {
|
|
379
|
+
await apiDeleteHelper(
|
|
380
|
+
() => ({
|
|
381
|
+
status: del.status,
|
|
382
|
+
data: del.item,
|
|
383
|
+
items: fetch.items,
|
|
384
|
+
options: del.options
|
|
385
|
+
}),
|
|
386
|
+
(data) => {
|
|
387
|
+
if (canUpdateRequest("delete", currentRequest)) del.status = data;
|
|
388
|
+
},
|
|
389
|
+
(data) => {
|
|
390
|
+
if (canUpdateRequest("delete", currentRequest)) del.options = data;
|
|
391
|
+
},
|
|
392
|
+
(data) => {
|
|
393
|
+
if (canUpdateRequest("delete", currentRequest)) del.item = data;
|
|
394
|
+
},
|
|
395
|
+
(data) => {
|
|
396
|
+
if (canUpdateRequest("delete", currentRequest)) fetch.items = data;
|
|
397
|
+
},
|
|
398
|
+
id,
|
|
399
|
+
{
|
|
400
|
+
...loaderOptions,
|
|
401
|
+
...opts,
|
|
402
|
+
signal: currentRequest.signal
|
|
403
|
+
}
|
|
404
|
+
);
|
|
405
|
+
} finally {
|
|
406
|
+
finishRequest("delete", currentRequest);
|
|
407
|
+
}
|
|
282
408
|
};
|
|
283
409
|
return {
|
|
284
410
|
// State and methods
|
|
@@ -299,6 +425,12 @@ export const usePageLoader = (loaderOptions) => {
|
|
|
299
425
|
addRun,
|
|
300
426
|
updateRun,
|
|
301
427
|
deleteRun,
|
|
428
|
+
cancelFetch,
|
|
429
|
+
cancelFind,
|
|
430
|
+
cancelAdd,
|
|
431
|
+
cancelUpdate,
|
|
432
|
+
cancelDelete,
|
|
433
|
+
cancelAll,
|
|
302
434
|
clearAll
|
|
303
435
|
};
|
|
304
436
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AxiosRequestConfig } from 'axios';
|
|
2
2
|
import type { IAPIOptions, IStatus } from '../types/lib.js';
|
|
3
3
|
export interface IBaseLoaderOptions {
|
|
4
4
|
isMock?: boolean;
|
|
5
5
|
params?: Record<string, any>;
|
|
6
6
|
expire?: number;
|
|
7
|
+
signal?: AbortSignal;
|
|
7
8
|
[key: string]: any;
|
|
8
9
|
}
|
|
9
10
|
export interface IRequestContext {
|
|
@@ -14,7 +15,9 @@ export interface IRequestContext {
|
|
|
14
15
|
}
|
|
15
16
|
export declare const checkExpiration: (timestamp: number | undefined, expire?: number) => boolean;
|
|
16
17
|
export declare const bindParamsToUrl: (urlTemplate: string, urlParams?: Record<string, any>) => string;
|
|
17
|
-
export declare const prepareRequestOptions: (baseOptions?: AxiosRequestConfig, requestOptions?: AxiosRequestConfig, params?: Record<string, any
|
|
18
|
+
export declare const prepareRequestOptions: (baseOptions?: AxiosRequestConfig, requestOptions?: AxiosRequestConfig, params?: Record<string, any>, signal?: AbortSignal) => AxiosRequestConfig;
|
|
19
|
+
export declare const omitLoaderSignal: <T extends Record<string, any>>(opts: T) => Omit<T, "signal">;
|
|
20
|
+
export declare const toSerializableRequestOptions: (options: AxiosRequestConfig) => Partial<AxiosRequestConfig>;
|
|
18
21
|
export declare const handleApiRequest: <T>(requestContext: IRequestContext, mockData: T | T[] | null, callbacks: {
|
|
19
22
|
onSuccess: (data: T, status?: number) => void;
|
|
20
23
|
onError: (error: any) => void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import axios from "axios";
|
|
1
2
|
import { ObjectHelper } from "../utils/ObjectHelper.js";
|
|
2
3
|
import { NewRequester } from "../lib/Requester.js";
|
|
3
4
|
import { _merge } from "#imports";
|
|
@@ -12,12 +13,60 @@ export const bindParamsToUrl = (urlTemplate, urlParams = {}) => {
|
|
|
12
13
|
});
|
|
13
14
|
return resultUrl;
|
|
14
15
|
};
|
|
15
|
-
export const prepareRequestOptions = (baseOptions, requestOptions, params) => {
|
|
16
|
+
export const prepareRequestOptions = (baseOptions, requestOptions, params, signal) => {
|
|
16
17
|
const options = _merge({}, baseOptions, requestOptions, {
|
|
17
|
-
params
|
|
18
|
+
params,
|
|
19
|
+
...signal ? {
|
|
20
|
+
signal
|
|
21
|
+
} : {}
|
|
18
22
|
});
|
|
19
23
|
return options;
|
|
20
24
|
};
|
|
25
|
+
export const omitLoaderSignal = (opts) => {
|
|
26
|
+
const {
|
|
27
|
+
signal: _signal,
|
|
28
|
+
...rest
|
|
29
|
+
} = opts;
|
|
30
|
+
return rest;
|
|
31
|
+
};
|
|
32
|
+
export const toSerializableRequestOptions = (options) => {
|
|
33
|
+
const {
|
|
34
|
+
adapter: _adapter,
|
|
35
|
+
cancelToken: _cancelToken,
|
|
36
|
+
paramsSerializer: _paramsSerializer,
|
|
37
|
+
signal: _signal,
|
|
38
|
+
transformRequest: _transformRequest,
|
|
39
|
+
transformResponse: _transformResponse,
|
|
40
|
+
validateStatus: _validateStatus,
|
|
41
|
+
...serializableOptions
|
|
42
|
+
} = options;
|
|
43
|
+
return JSON.parse(JSON.stringify(serializableOptions));
|
|
44
|
+
};
|
|
45
|
+
const createAbortError = () => ({
|
|
46
|
+
code: "ERR_CANCELED",
|
|
47
|
+
name: "AbortError",
|
|
48
|
+
message: "Request canceled"
|
|
49
|
+
});
|
|
50
|
+
const isAbortError = (error) => {
|
|
51
|
+
return axios.isCancel(error) || error?.code === "ERR_CANCELED" || error?.name === "AbortError";
|
|
52
|
+
};
|
|
53
|
+
const wait = (ms, signal) => new Promise((resolve, reject) => {
|
|
54
|
+
if (signal?.aborted) {
|
|
55
|
+
reject(createAbortError());
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const timeout = setTimeout(() => {
|
|
59
|
+
signal?.removeEventListener?.("abort", abort);
|
|
60
|
+
resolve();
|
|
61
|
+
}, ms);
|
|
62
|
+
const abort = () => {
|
|
63
|
+
clearTimeout(timeout);
|
|
64
|
+
reject(createAbortError());
|
|
65
|
+
};
|
|
66
|
+
signal?.addEventListener?.("abort", abort, {
|
|
67
|
+
once: true
|
|
68
|
+
});
|
|
69
|
+
});
|
|
21
70
|
export const handleApiRequest = async (requestContext, mockData, callbacks) => {
|
|
22
71
|
const {
|
|
23
72
|
url,
|
|
@@ -27,13 +76,14 @@ export const handleApiRequest = async (requestContext, mockData, callbacks) => {
|
|
|
27
76
|
} = requestContext;
|
|
28
77
|
try {
|
|
29
78
|
if (mockData) {
|
|
30
|
-
await
|
|
79
|
+
await wait(300, options.signal);
|
|
31
80
|
callbacks.onSuccess(mockData);
|
|
32
81
|
} else {
|
|
33
82
|
const response = await NewRequester.create(method, url, data, options);
|
|
34
83
|
callbacks.onSuccess(response.data, response.status);
|
|
35
84
|
}
|
|
36
85
|
} catch (error) {
|
|
86
|
+
if (isAbortError(error)) return;
|
|
37
87
|
callbacks.onError(error);
|
|
38
88
|
} finally {
|
|
39
89
|
callbacks.onComplete?.();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const createCancelableRequest = (externalSignal) => {
|
|
2
|
+
const controller = new AbortController();
|
|
3
|
+
const abort = () => {
|
|
4
|
+
controller.abort();
|
|
5
|
+
};
|
|
6
|
+
if (externalSignal) {
|
|
7
|
+
if (externalSignal.aborted) {
|
|
8
|
+
abort();
|
|
9
|
+
} else {
|
|
10
|
+
externalSignal.addEventListener("abort", abort, {
|
|
11
|
+
once: true
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
controller,
|
|
17
|
+
signal: controller.signal,
|
|
18
|
+
cleanup: () => {
|
|
19
|
+
externalSignal?.removeEventListener("abort", abort);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
};
|