@guebbit/vue-toolkit 1.0.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/CHANGELOG +1 -0
- package/LICENSE +661 -0
- package/README.md +3 -0
- package/dist/composables/structureDataManagement.js +238 -0
- package/dist/composables/structureDataManagement.js.map +1 -0
- package/dist/composables/structureFormValidation.js +3 -0
- package/dist/composables/structureFormValidation.js.map +1 -0
- package/dist/composables/structureRestApi.js +606 -0
- package/dist/composables/structureRestApi.js.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/stores/core.js +36 -0
- package/dist/stores/core.js.map +1 -0
- package/dist/stores/notifications.js +93 -0
- package/dist/stores/notifications.js.map +1 -0
- package/dist/types/composables/structureDataManagement.d.ts +29 -0
- package/dist/types/composables/structureDataManagement.d.ts.map +1 -0
- package/dist/types/composables/structureFormValidation.d.ts +1 -0
- package/dist/types/composables/structureFormValidation.d.ts.map +1 -0
- package/dist/types/composables/structureRestApi.d.ts +128 -0
- package/dist/types/composables/structureRestApi.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/stores/core.d.ts +20 -0
- package/dist/types/stores/core.d.ts.map +1 -0
- package/dist/types/stores/notifications.d.ts +120 -0
- package/dist/types/stores/notifications.d.ts.map +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1,606 @@
|
|
|
1
|
+
import { computed, ref } from "vue";
|
|
2
|
+
import { useStructureDataManagement } from "../index";
|
|
3
|
+
/**
|
|
4
|
+
* Time To Live and Last Update
|
|
5
|
+
* Optimize fetch requests by caching data and preventing unnecessary requests
|
|
6
|
+
*/
|
|
7
|
+
export var ELastUpdateKeywords;
|
|
8
|
+
(function (ELastUpdateKeywords) {
|
|
9
|
+
ELastUpdateKeywords["ALL"] = "_all";
|
|
10
|
+
ELastUpdateKeywords["TARGET"] = "_target";
|
|
11
|
+
ELastUpdateKeywords["PARENT"] = "_parent";
|
|
12
|
+
ELastUpdateKeywords["ONLINE"] = "_online";
|
|
13
|
+
ELastUpdateKeywords["GENERIC"] = "_generic";
|
|
14
|
+
})(ELastUpdateKeywords || (ELastUpdateKeywords = {}));
|
|
15
|
+
export const useStructureRestApi = ({ identifiers = "id", loadingKey = crypto.randomUUID(), TTL = 3600000, // 1 hour
|
|
16
|
+
delimiter = "|", getLoading, setLoading } = {}) => {
|
|
17
|
+
/**
|
|
18
|
+
* Inherited
|
|
19
|
+
*/
|
|
20
|
+
const { createIdentifier, identifier: identifierKey, itemDictionary, itemList, setRecords, resetRecords, getRecord, getRecords, addRecord, addRecords, editRecord, deleteRecord, selectedIdentifier, selectedRecord,
|
|
21
|
+
// Pagination
|
|
22
|
+
pageCurrent, pageSize, pageTotal, pageOffset, pageItemList,
|
|
23
|
+
// belongsTo relationship
|
|
24
|
+
parentHasMany, addToParent, removeFromParent, removeDuplicateChildren, getRecordsByParent, getListByParent, } = useStructureDataManagement(identifiers, delimiter);
|
|
25
|
+
/**
|
|
26
|
+
* loadings
|
|
27
|
+
*/
|
|
28
|
+
// loading mutators
|
|
29
|
+
const startLoading = (postfix = "") => loadingKey && setLoading ? setLoading(loadingKey + postfix, true) : _loading.value = true;
|
|
30
|
+
const stopLoading = (postfix = "") => loadingKey && setLoading ? setLoading(loadingKey + postfix, false) : _loading.value = false;
|
|
31
|
+
// Check if it's loading
|
|
32
|
+
const _loading = ref(false);
|
|
33
|
+
const loading = computed(() => getLoading ? getLoading(loadingKey) : _loading.value);
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
const lastUpdate = {
|
|
38
|
+
[ELastUpdateKeywords.ALL]: 0,
|
|
39
|
+
[ELastUpdateKeywords.TARGET]: {},
|
|
40
|
+
[ELastUpdateKeywords.PARENT]: {},
|
|
41
|
+
[ELastUpdateKeywords.ONLINE]: {},
|
|
42
|
+
[ELastUpdateKeywords.GENERIC]: {}
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Reset cache age
|
|
46
|
+
* @param branch
|
|
47
|
+
*/
|
|
48
|
+
const resetLastUpdate = (branch) => {
|
|
49
|
+
if (branch === ELastUpdateKeywords.ALL) {
|
|
50
|
+
lastUpdate[branch] = 0;
|
|
51
|
+
}
|
|
52
|
+
else if (branch) {
|
|
53
|
+
// @ts-expect-error would be a pain to fully type and it's not needed
|
|
54
|
+
lastUpdate[branch] = {};
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
lastUpdate[ELastUpdateKeywords.ALL] = 0;
|
|
58
|
+
lastUpdate[ELastUpdateKeywords.TARGET] = {};
|
|
59
|
+
lastUpdate[ELastUpdateKeywords.PARENT] = {};
|
|
60
|
+
lastUpdate[ELastUpdateKeywords.ONLINE] = {};
|
|
61
|
+
lastUpdate[ELastUpdateKeywords.GENERIC] = {};
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Check if the last update was within the TTL
|
|
66
|
+
* True = still valid
|
|
67
|
+
*
|
|
68
|
+
* @param key
|
|
69
|
+
* @param branch
|
|
70
|
+
*/
|
|
71
|
+
const getLastUpdate = (key = "", branch = ELastUpdateKeywords.GENERIC) => Date.now() - (
|
|
72
|
+
// if ELastUpdateKeywords.ALL I ignore the key
|
|
73
|
+
branch === ELastUpdateKeywords.ALL ? lastUpdate[ELastUpdateKeywords.ALL] :
|
|
74
|
+
// @ts-expect-error too intricate to typesafe. It is safe.
|
|
75
|
+
lastUpdate[branch][key]) < TTL;
|
|
76
|
+
/**
|
|
77
|
+
* Check if the last update was within the TTL
|
|
78
|
+
* True = still valid
|
|
79
|
+
*
|
|
80
|
+
* @param value
|
|
81
|
+
* @param key
|
|
82
|
+
* @param branch
|
|
83
|
+
*/
|
|
84
|
+
const editLastUpdate = (value = 0, key = "", branch = ELastUpdateKeywords.GENERIC) => {
|
|
85
|
+
// if ELastUpdateKeywords.ALL I ignore the key
|
|
86
|
+
if (branch === ELastUpdateKeywords.ALL) {
|
|
87
|
+
lastUpdate[ELastUpdateKeywords.ALL] = value;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// @ts-expect-error too intricate to typesafe. It is safe.
|
|
91
|
+
lastUpdate[branch][key] = value;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Same as getLastUpdate, but I update lastUpdate too
|
|
96
|
+
* If it was invalid, I update it because I know I will update the data right after this check and return false.
|
|
97
|
+
*
|
|
98
|
+
* @param key
|
|
99
|
+
* @param branch
|
|
100
|
+
*/
|
|
101
|
+
const checkAndEditLastUpdate = (key = "", branch = ELastUpdateKeywords.GENERIC) => {
|
|
102
|
+
if (getLastUpdate(key, branch)) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
editLastUpdate(Date.now());
|
|
106
|
+
return false;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Common save items routine on various fetches
|
|
110
|
+
*
|
|
111
|
+
* @param items
|
|
112
|
+
* @param merge
|
|
113
|
+
* @param onSave - customized single item operations
|
|
114
|
+
*/
|
|
115
|
+
function saveRecords(items = [], merge = false, onSave) {
|
|
116
|
+
for (let i = 0, len = items.length; i < len; i++) {
|
|
117
|
+
if (!items[i])
|
|
118
|
+
continue;
|
|
119
|
+
if (merge)
|
|
120
|
+
editRecord(items[i]);
|
|
121
|
+
else
|
|
122
|
+
addRecord(items[i]);
|
|
123
|
+
if (onSave)
|
|
124
|
+
onSave(items[i]);
|
|
125
|
+
}
|
|
126
|
+
return items;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Generic fetch for all types of requests,
|
|
130
|
+
* Just for loading management and generic TTL check.
|
|
131
|
+
* WARNING: If a fetch request is cached, the promise chain WILL NOT BE APPLIED
|
|
132
|
+
* WARNING: TTL fast response doesn't return anything since it's a generic fetch and doesn't know what to return
|
|
133
|
+
*
|
|
134
|
+
*
|
|
135
|
+
* @key F - type of the response, that can be anything
|
|
136
|
+
* @param asyncCall - call that we are going to make
|
|
137
|
+
* @param forced
|
|
138
|
+
* @param loading
|
|
139
|
+
* @param lastUpdateKey
|
|
140
|
+
* @param loadingKey
|
|
141
|
+
*/
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
143
|
+
const fetchAny = (asyncCall, { forced, loading = true, lastUpdateKey = "", loadingKey } = {}) => {
|
|
144
|
+
// If TTL is not expired, the current stored data is still valid
|
|
145
|
+
// If no TTL name is provided, we ignore the TTL altogether
|
|
146
|
+
if (!forced && (lastUpdateKey && checkAndEditLastUpdate(lastUpdateKey)))
|
|
147
|
+
// WARNING: We don't know what kind of data was about to be fetched, so it will be empty
|
|
148
|
+
// eslint-disable-next-line unicorn/no-useless-undefined
|
|
149
|
+
return Promise.resolve(undefined);
|
|
150
|
+
//
|
|
151
|
+
if (loading)
|
|
152
|
+
startLoading(loadingKey);
|
|
153
|
+
// actual request
|
|
154
|
+
return asyncCall()
|
|
155
|
+
.catch((error) => {
|
|
156
|
+
// Reset TTL in case of error
|
|
157
|
+
if (lastUpdateKey)
|
|
158
|
+
editLastUpdate(0, lastUpdateKey);
|
|
159
|
+
throw error;
|
|
160
|
+
})
|
|
161
|
+
.finally(() => loading && stopLoading(loadingKey));
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Get ALL items from server
|
|
165
|
+
* Example: fetchAll retrieve a list of items and fetchTarget retrieve a single item WITH DETAILS
|
|
166
|
+
* WARNING: If a fetch request is cached, the promise chain WILL NOT BE APPLIED
|
|
167
|
+
*
|
|
168
|
+
* @param apiCall
|
|
169
|
+
* @param forced
|
|
170
|
+
* @param loading
|
|
171
|
+
* @param merge
|
|
172
|
+
* @param lastUpdateKey
|
|
173
|
+
* @param loadingKey
|
|
174
|
+
* @param mismatch
|
|
175
|
+
*/
|
|
176
|
+
const fetchAll = (apiCall, { forced, loading = true, merge, lastUpdateKey = "", loadingKey } = {},
|
|
177
|
+
/**
|
|
178
|
+
* When the fetchAll and fetchTarget api calls single items are different:
|
|
179
|
+
* they don't have to be in sync nor the fetchAll must overwrite the fetchTarget item.
|
|
180
|
+
* Moreover, instead of fully replacing old data, it will be merged
|
|
181
|
+
*/
|
|
182
|
+
mismatch = false) => {
|
|
183
|
+
// If TTL is not expired, the current stored data is still valid
|
|
184
|
+
// If the TTL name is provided: it becomes a GENERIC TTL check
|
|
185
|
+
if (!forced && (lastUpdateKey ? checkAndEditLastUpdate(lastUpdateKey) : checkAndEditLastUpdate("", ELastUpdateKeywords.ALL)))
|
|
186
|
+
return Promise.resolve(itemDictionary.value);
|
|
187
|
+
if (loading)
|
|
188
|
+
startLoading(loadingKey);
|
|
189
|
+
// request
|
|
190
|
+
return apiCall()
|
|
191
|
+
.then((items = []) => {
|
|
192
|
+
const now = Date.now();
|
|
193
|
+
return saveRecords(items, merge, (item) => {
|
|
194
|
+
if (!mismatch)
|
|
195
|
+
editLastUpdate(now, createIdentifier(item), ELastUpdateKeywords.TARGET);
|
|
196
|
+
});
|
|
197
|
+
})
|
|
198
|
+
.catch((error) => {
|
|
199
|
+
// Reset TTL in case of error
|
|
200
|
+
editLastUpdate(0, lastUpdateKey, ELastUpdateKeywords.ALL);
|
|
201
|
+
throw error;
|
|
202
|
+
})
|
|
203
|
+
.finally(() => loading && stopLoading(loadingKey));
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Same as fetchAll, but with a parent identifier (belongsTo relationship)
|
|
207
|
+
* WARNING: If a fetch request is cached, the promise chain WILL NOT BE APPLIED
|
|
208
|
+
*
|
|
209
|
+
* @param apiCall
|
|
210
|
+
* @param parentId - identifier of parent
|
|
211
|
+
* WARNING: in case of multiple identifiers, createIdentifier(id) must be used!
|
|
212
|
+
* @param forced
|
|
213
|
+
* @param loading
|
|
214
|
+
* @param merge
|
|
215
|
+
* @param lastUpdateKey
|
|
216
|
+
* @param loadingKey
|
|
217
|
+
* @param mismatch
|
|
218
|
+
*/
|
|
219
|
+
const fetchByParent = (apiCall, parentId, { forced, loading = true, merge, lastUpdateKey = "", loadingKey } = {},
|
|
220
|
+
/**
|
|
221
|
+
* Similar reasoning as fetchAll mismatch
|
|
222
|
+
*/
|
|
223
|
+
mismatch = false) => {
|
|
224
|
+
// If TTL is not expired, the current stored data is still valid
|
|
225
|
+
if (!forced && checkAndEditLastUpdate(lastUpdateKey + parentId, ELastUpdateKeywords.PARENT))
|
|
226
|
+
return Promise.resolve(getListByParent(parentId));
|
|
227
|
+
if (loading)
|
|
228
|
+
startLoading(loadingKey);
|
|
229
|
+
// request
|
|
230
|
+
return apiCall()
|
|
231
|
+
.then((items = []) => {
|
|
232
|
+
const now = Date.now();
|
|
233
|
+
for (let i = 0, len = items.length; i < len; i++) {
|
|
234
|
+
if (!items[i])
|
|
235
|
+
continue;
|
|
236
|
+
addToParent(parentId, createIdentifier(items[i]));
|
|
237
|
+
// if mismatch, we don't want to overwrite the fetchTarget's item so we merge
|
|
238
|
+
if (merge || mismatch)
|
|
239
|
+
editRecord(items[i]);
|
|
240
|
+
else
|
|
241
|
+
addRecord(items[i]);
|
|
242
|
+
// If no mismatch, we can update the target's lastUpdate too
|
|
243
|
+
if (!mismatch)
|
|
244
|
+
editLastUpdate(now, createIdentifier(items[i]), ELastUpdateKeywords.TARGET);
|
|
245
|
+
}
|
|
246
|
+
removeDuplicateChildren(parentId);
|
|
247
|
+
return items;
|
|
248
|
+
})
|
|
249
|
+
.catch((error) => {
|
|
250
|
+
// Reset TTL in case of error
|
|
251
|
+
editLastUpdate(0, lastUpdateKey + parentId, ELastUpdateKeywords.PARENT);
|
|
252
|
+
throw error;
|
|
253
|
+
})
|
|
254
|
+
.finally(() => loading && stopLoading(loadingKey));
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* Get target item from server
|
|
258
|
+
* WARNING: If a fetch request is cached, the promise chain WILL NOT BE APPLIED
|
|
259
|
+
*
|
|
260
|
+
* @param apiCall
|
|
261
|
+
* @param id - can be undefined if we don't know yet the id, no TTL check will be done thought
|
|
262
|
+
* WARNING: in case of multiple identifiers, createIdentifier(id) must be used!
|
|
263
|
+
* @param forced
|
|
264
|
+
* @param loading
|
|
265
|
+
* @param merge
|
|
266
|
+
* @param lastUpdateKey
|
|
267
|
+
* @param loadingKey
|
|
268
|
+
*/
|
|
269
|
+
const fetchTarget = (apiCall, id, { forced, loading = true, merge, lastUpdateKey = "", loadingKey } = {}) => {
|
|
270
|
+
// If TTL is not expired, the current stored data is still valid
|
|
271
|
+
// (if id is not provided, we must force through the request)
|
|
272
|
+
if (id && !forced && checkAndEditLastUpdate(lastUpdateKey + id, ELastUpdateKeywords.TARGET))
|
|
273
|
+
return Promise.resolve(getRecord(id));
|
|
274
|
+
if (loading)
|
|
275
|
+
startLoading(loadingKey);
|
|
276
|
+
// request
|
|
277
|
+
return apiCall()
|
|
278
|
+
.then((item) => saveRecords([item], merge, (item) => {
|
|
279
|
+
// in case it wasn't provided the id, we must update the lastUpdate now
|
|
280
|
+
editLastUpdate(Date.now(), lastUpdateKey + createIdentifier(item), ELastUpdateKeywords.TARGET);
|
|
281
|
+
})[0])
|
|
282
|
+
.catch((error) => {
|
|
283
|
+
// Reset TTL in case of error
|
|
284
|
+
if (id)
|
|
285
|
+
editLastUpdate(0, lastUpdateKey + id, ELastUpdateKeywords.TARGET);
|
|
286
|
+
throw error;
|
|
287
|
+
})
|
|
288
|
+
.finally(() => loading && stopLoading(loadingKey));
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* Fetch target but with multiple ids
|
|
292
|
+
* WARNING: If a fetch request is cached, the promise chain WILL NOT BE APPLIED
|
|
293
|
+
*
|
|
294
|
+
* @param apiCall
|
|
295
|
+
* @param ids - Array of ids - WARNING: in case of multiple identifiers, createIdentifier(id) must be used! * @param forced
|
|
296
|
+
* @param forced
|
|
297
|
+
* @param loading
|
|
298
|
+
* @param merge
|
|
299
|
+
* @param loadingKey
|
|
300
|
+
* @param lastUpdateKey
|
|
301
|
+
*/
|
|
302
|
+
const fetchMultiple = (apiCall, ids, { forced, loading = true, merge, loadingKey, lastUpdateKey = "" } = {}) => {
|
|
303
|
+
// nothing to search
|
|
304
|
+
if (!ids || ids.length === 0)
|
|
305
|
+
return Promise.resolve([]);
|
|
306
|
+
let i;
|
|
307
|
+
/**
|
|
308
|
+
* expiredIds are Ids with TTL NOT expired, they will be fetched,
|
|
309
|
+
* cachedIds will just get the already cached data
|
|
310
|
+
*/
|
|
311
|
+
const expiredIds = [];
|
|
312
|
+
const cachedIds = [];
|
|
313
|
+
// Check which ids are expired and in need of fetch
|
|
314
|
+
// REMEMBER: checkAndEditLastUpdate will set Date.now() to lastUpdate if "false",
|
|
315
|
+
// because all expired Ids will be renew just after this
|
|
316
|
+
for (const id of ids) {
|
|
317
|
+
if (forced || !checkAndEditLastUpdate(lastUpdateKey + id, ELastUpdateKeywords.TARGET))
|
|
318
|
+
expiredIds.push(id);
|
|
319
|
+
else
|
|
320
|
+
cachedIds.push(id);
|
|
321
|
+
}
|
|
322
|
+
// items that I already have
|
|
323
|
+
const cachedItems = cachedIds.map(id => getRecord(id));
|
|
324
|
+
// If no ids are expired, no need to make a fetch
|
|
325
|
+
if (expiredIds.length === 0)
|
|
326
|
+
return Promise.resolve(cachedItems);
|
|
327
|
+
if (loading)
|
|
328
|
+
startLoading(loadingKey);
|
|
329
|
+
// request
|
|
330
|
+
return apiCall()
|
|
331
|
+
.then((items = []) => {
|
|
332
|
+
const now = Date.now();
|
|
333
|
+
// return all requested items, even the already cached ones
|
|
334
|
+
return [
|
|
335
|
+
...saveRecords(items, merge, (item) => {
|
|
336
|
+
editLastUpdate(now, createIdentifier(item), ELastUpdateKeywords.TARGET);
|
|
337
|
+
}),
|
|
338
|
+
...cachedItems
|
|
339
|
+
];
|
|
340
|
+
})
|
|
341
|
+
.catch((error) => {
|
|
342
|
+
// Reset TTL in case of error
|
|
343
|
+
for (i = expiredIds.length; i--;)
|
|
344
|
+
if (expiredIds[i])
|
|
345
|
+
editLastUpdate(0, expiredIds[i], ELastUpdateKeywords.TARGET);
|
|
346
|
+
throw error;
|
|
347
|
+
})
|
|
348
|
+
.finally(() => loading && stopLoading(loadingKey));
|
|
349
|
+
};
|
|
350
|
+
/**
|
|
351
|
+
* Cached items ID divided per page, itemDictionary will hold the item data.
|
|
352
|
+
* Stringified query => page => array if ids of the found products
|
|
353
|
+
*/
|
|
354
|
+
const searchCached = ref({});
|
|
355
|
+
/**
|
|
356
|
+
* Create a stable and always-the-same key from an object
|
|
357
|
+
* @param object
|
|
358
|
+
*/
|
|
359
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
360
|
+
const searchKeyGen = (object = {}) => JSON.stringify(object, Object.keys(object).toSorted());
|
|
361
|
+
/**
|
|
362
|
+
* Get search page based on key and page number
|
|
363
|
+
* @param key - stringified search parameters
|
|
364
|
+
* @param page - page
|
|
365
|
+
*/
|
|
366
|
+
const searchGet = (key, page = 1) => getRecords(searchCached.value[typeof key === "string" ? key : searchKeyGen(key)]?.[page]);
|
|
367
|
+
/**
|
|
368
|
+
* I clean up all expired searches OR, if they are 100+, the old ones.
|
|
369
|
+
*/
|
|
370
|
+
const searchCleanup = () => {
|
|
371
|
+
const MAX_SEARCHES = 50;
|
|
372
|
+
// Remove expired entries
|
|
373
|
+
const validEntries = Object.entries(lastUpdate[ELastUpdateKeywords.ONLINE])
|
|
374
|
+
.filter(([_, ttl]) => ttl < Date.now());
|
|
375
|
+
// If there are too many valid entries, sort descending (newest first) so later the oldest will be trimmed
|
|
376
|
+
if (validEntries.length > MAX_SEARCHES)
|
|
377
|
+
validEntries.sort((a, b) => b[1] - a[1]);
|
|
378
|
+
// rebuild lastUpdate
|
|
379
|
+
lastUpdate[ELastUpdateKeywords.ONLINE] = Object.fromEntries(validEntries.slice(0, 100));
|
|
380
|
+
};
|
|
381
|
+
/**
|
|
382
|
+
* Fetch items as a search.
|
|
383
|
+
* Since we can't have a full picture of what the server has in terms of items and search parameters,
|
|
384
|
+
* caching and optimizing need many extra steps.
|
|
385
|
+
*
|
|
386
|
+
* We will cache the items like normal BUT the TTL will be checked on the stringified search parameters.
|
|
387
|
+
* In searchCached we will store the search by the same key and divided in an array of pages were every page contain an array of id of items
|
|
388
|
+
* NOTE: I don't care about page size, I just save for every page all items that are returned from the server.
|
|
389
|
+
*
|
|
390
|
+
* WARNING: If a fetch request is cached, the promise chain WILL NOT BE APPLIED
|
|
391
|
+
*
|
|
392
|
+
* @param apiCall
|
|
393
|
+
* @param filters - search parameters
|
|
394
|
+
* @param page - WARNING, THIS FUNCTION ONLY
|
|
395
|
+
* It's not the pagination filter but just for info
|
|
396
|
+
* because I can't know how the page parameter is handled
|
|
397
|
+
* @param forced
|
|
398
|
+
* @param loading
|
|
399
|
+
* @param merge
|
|
400
|
+
* @param lastUpdateKey
|
|
401
|
+
* @param loadingKey
|
|
402
|
+
* @param mismatch
|
|
403
|
+
*/
|
|
404
|
+
const fetchSearch = (apiCall, filters = {}, page = 1, { forced, loading = true, merge, lastUpdateKey = "", loadingKey } = {},
|
|
405
|
+
/**
|
|
406
|
+
* Similar reasoning as fetchAll mismatch
|
|
407
|
+
*/
|
|
408
|
+
mismatch = false) => {
|
|
409
|
+
// Create search key using all the filter parameters
|
|
410
|
+
const searchKey = searchKeyGen(filters);
|
|
411
|
+
const searchTTLkey = lastUpdateKey + searchKey + page;
|
|
412
|
+
// Instead of regular checkAndEditLastUpdate, I clean up all expired searches and check if the ID is still present
|
|
413
|
+
searchCleanup();
|
|
414
|
+
// TTL is monodimensional so the page will be added to the key (TTL ONLY)
|
|
415
|
+
if (!forced && (searchTTLkey) in lastUpdate[ELastUpdateKeywords.ONLINE])
|
|
416
|
+
return Promise.resolve(getRecords(searchCached.value[searchKey]?.[page]));
|
|
417
|
+
// Then I manually save the TTL (since I'm not using checkAndEditLastUpdate shortcut)
|
|
418
|
+
lastUpdate[ELastUpdateKeywords.ONLINE][searchTTLkey] = Date.now();
|
|
419
|
+
if (loading)
|
|
420
|
+
startLoading(loadingKey);
|
|
421
|
+
// request
|
|
422
|
+
return apiCall()
|
|
423
|
+
.then((items = []) => {
|
|
424
|
+
const now = Date.now();
|
|
425
|
+
// Empty array to be filled with items ids
|
|
426
|
+
if (!(searchKey in searchCached.value))
|
|
427
|
+
searchCached.value[searchKey] = [];
|
|
428
|
+
searchCached.value[searchKey][page] = [];
|
|
429
|
+
saveRecords(items, merge, (item) => {
|
|
430
|
+
searchCached.value[searchKey][page].push(createIdentifier(item));
|
|
431
|
+
if (!mismatch)
|
|
432
|
+
editLastUpdate(now, createIdentifier(item), ELastUpdateKeywords.TARGET);
|
|
433
|
+
});
|
|
434
|
+
return items;
|
|
435
|
+
})
|
|
436
|
+
.catch((error) => {
|
|
437
|
+
// Reset TTL in case of error
|
|
438
|
+
editLastUpdate(0, searchTTLkey, ELastUpdateKeywords.ONLINE);
|
|
439
|
+
throw error;
|
|
440
|
+
})
|
|
441
|
+
.finally(() => loading && stopLoading(loadingKey));
|
|
442
|
+
};
|
|
443
|
+
/**
|
|
444
|
+
* dummyData: Create data immediately and then update it later
|
|
445
|
+
* when the server returns the real data
|
|
446
|
+
*
|
|
447
|
+
* @param apiCall
|
|
448
|
+
* @param dummyData
|
|
449
|
+
* @param loading
|
|
450
|
+
* @param lastUpdateKey
|
|
451
|
+
* @param loadingKey
|
|
452
|
+
* @param fetchLike - data of the created item will be considered fetched like in fetchTarget
|
|
453
|
+
*/
|
|
454
|
+
const createTarget = (apiCall, dummyData, { loading = true, lastUpdateKey = "", loadingKey } = {}, fetchLike = true) => {
|
|
455
|
+
const temporaryId = crypto.randomUUID();
|
|
456
|
+
// Create temporary item with temporary id for instantaneity
|
|
457
|
+
if (dummyData)
|
|
458
|
+
editRecord(dummyData, temporaryId, true);
|
|
459
|
+
if (loading)
|
|
460
|
+
startLoading(loadingKey);
|
|
461
|
+
// request
|
|
462
|
+
return apiCall()
|
|
463
|
+
.then((item) => {
|
|
464
|
+
if (!item)
|
|
465
|
+
return;
|
|
466
|
+
const id = createIdentifier(item);
|
|
467
|
+
// Remove the temporary item and add the real one
|
|
468
|
+
if (dummyData)
|
|
469
|
+
deleteRecord(temporaryId);
|
|
470
|
+
addRecord(item);
|
|
471
|
+
// If it can be treated as a fetchTarget
|
|
472
|
+
if (fetchLike)
|
|
473
|
+
editLastUpdate(Date.now(), lastUpdateKey + id, ELastUpdateKeywords.TARGET);
|
|
474
|
+
return getRecord(id);
|
|
475
|
+
})
|
|
476
|
+
.catch((error) => {
|
|
477
|
+
// rollback
|
|
478
|
+
deleteRecord(temporaryId);
|
|
479
|
+
throw error;
|
|
480
|
+
})
|
|
481
|
+
.finally(() => loading && stopLoading(loadingKey));
|
|
482
|
+
};
|
|
483
|
+
/**
|
|
484
|
+
* Update an existing record
|
|
485
|
+
*
|
|
486
|
+
* @key F - type of the response, that can be something else than T
|
|
487
|
+
* @param apiCall
|
|
488
|
+
* @param itemData
|
|
489
|
+
* @param id - if undefined it will be inferred
|
|
490
|
+
* WARNING: in case of multiple identifiers, createIdentifier(id) must be used!
|
|
491
|
+
* @param loading
|
|
492
|
+
* @param merge
|
|
493
|
+
* @param lastUpdateKey
|
|
494
|
+
* @param loadingKey
|
|
495
|
+
* @param fetchLike - data will be considered fetched like in fetchTarget
|
|
496
|
+
* @param fetchAgain - after the update, the call can return the updated item, update in this case (for consistency)
|
|
497
|
+
*/
|
|
498
|
+
const updateTarget = (apiCall, itemData, id, { loading = true, merge, lastUpdateKey = "", loadingKey } = {}, fetchLike = true, fetchAgain = true) => {
|
|
499
|
+
// to be used in case of error and revert is needed
|
|
500
|
+
const oldItemData = getRecord(id);
|
|
501
|
+
// for instantaneity, but can be inconsistent
|
|
502
|
+
editRecord(itemData, id, true);
|
|
503
|
+
if (loading)
|
|
504
|
+
startLoading(loadingKey);
|
|
505
|
+
return apiCall()
|
|
506
|
+
// If the apiCall returns the updated item, editRecord will be called again to ensure data consistency
|
|
507
|
+
.then((data) => {
|
|
508
|
+
if (fetchAgain) {
|
|
509
|
+
if (merge)
|
|
510
|
+
editRecord(data, id);
|
|
511
|
+
else
|
|
512
|
+
addRecord(data);
|
|
513
|
+
}
|
|
514
|
+
// If it can be treated as a fetchTarget
|
|
515
|
+
if (fetchLike || fetchAgain)
|
|
516
|
+
editLastUpdate(Date.now(), lastUpdateKey + id, ELastUpdateKeywords.TARGET);
|
|
517
|
+
return data;
|
|
518
|
+
})
|
|
519
|
+
.catch((error) => {
|
|
520
|
+
// Rollback in case of error
|
|
521
|
+
if (oldItemData)
|
|
522
|
+
editRecord(oldItemData, id);
|
|
523
|
+
throw error;
|
|
524
|
+
})
|
|
525
|
+
.finally(() => loading && stopLoading(loadingKey));
|
|
526
|
+
};
|
|
527
|
+
/**
|
|
528
|
+
*
|
|
529
|
+
* @key F - type of the response
|
|
530
|
+
* @param apiCall
|
|
531
|
+
* @param id - WARNING: in case of multiple identifiers, createIdentifier(id) must be used!
|
|
532
|
+
* @param loading
|
|
533
|
+
* @param loadingKey - custom loading key
|
|
534
|
+
*/
|
|
535
|
+
const deleteTarget = (apiCall, id, { loading = true, loadingKey } = {}) => {
|
|
536
|
+
// in case revert is needed
|
|
537
|
+
const oldItemData = getRecord(id);
|
|
538
|
+
deleteRecord(id);
|
|
539
|
+
if (loading)
|
|
540
|
+
startLoading(loadingKey);
|
|
541
|
+
return apiCall()
|
|
542
|
+
.catch((error) => {
|
|
543
|
+
// Rollback in case of error
|
|
544
|
+
if (oldItemData)
|
|
545
|
+
addRecord(oldItemData);
|
|
546
|
+
throw error;
|
|
547
|
+
})
|
|
548
|
+
.finally(() => loading && stopLoading(loadingKey));
|
|
549
|
+
};
|
|
550
|
+
return {
|
|
551
|
+
// settings (default value could be necessary)
|
|
552
|
+
createIdentifier,
|
|
553
|
+
identifierKey,
|
|
554
|
+
loadingKey,
|
|
555
|
+
// core structure
|
|
556
|
+
itemDictionary,
|
|
557
|
+
itemList,
|
|
558
|
+
setRecords,
|
|
559
|
+
resetRecords,
|
|
560
|
+
getRecord,
|
|
561
|
+
getRecords,
|
|
562
|
+
addRecord,
|
|
563
|
+
addRecords,
|
|
564
|
+
editRecord,
|
|
565
|
+
deleteRecord,
|
|
566
|
+
selectedIdentifier,
|
|
567
|
+
selectedRecord,
|
|
568
|
+
// Pagination
|
|
569
|
+
pageCurrent,
|
|
570
|
+
pageSize,
|
|
571
|
+
pageTotal,
|
|
572
|
+
pageOffset,
|
|
573
|
+
pageItemList,
|
|
574
|
+
// belongsTo relationship
|
|
575
|
+
parentHasMany,
|
|
576
|
+
addToParent,
|
|
577
|
+
removeFromParent,
|
|
578
|
+
removeDuplicateChildren,
|
|
579
|
+
getRecordsByParent,
|
|
580
|
+
getListByParent,
|
|
581
|
+
// api calls
|
|
582
|
+
startLoading,
|
|
583
|
+
stopLoading,
|
|
584
|
+
loading,
|
|
585
|
+
lastUpdate,
|
|
586
|
+
resetLastUpdate,
|
|
587
|
+
getLastUpdate,
|
|
588
|
+
editLastUpdate,
|
|
589
|
+
checkAndEditLastUpdate,
|
|
590
|
+
saveRecords,
|
|
591
|
+
fetchAny,
|
|
592
|
+
fetchAll,
|
|
593
|
+
fetchByParent,
|
|
594
|
+
fetchTarget,
|
|
595
|
+
fetchMultiple,
|
|
596
|
+
searchCached,
|
|
597
|
+
searchKeyGen,
|
|
598
|
+
searchGet,
|
|
599
|
+
searchCleanup,
|
|
600
|
+
fetchSearch,
|
|
601
|
+
createTarget,
|
|
602
|
+
updateTarget,
|
|
603
|
+
deleteTarget
|
|
604
|
+
};
|
|
605
|
+
};
|
|
606
|
+
//# sourceMappingURL=structureRestApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structureRestApi.js","sourceRoot":"","sources":["../../src/composables/structureRestApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAsDtD;;;GAGG;AACH,MAAM,CAAN,IAAY,mBAMX;AAND,WAAY,mBAAmB;IAC3B,mCA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AC,WAAW,CAAC,CAAC;YAC3B,MAAM,KAAK,CAAC;QAChB,CAAC,CAAC;aACD,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,IAAI,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC;IAEF,OAAO;QACH,8CAA8C;QAC9C,gBAAgB;QAChB,aAAa;QACb,UAAU;QAEV,iBAAiB;QACjB,cAAc;QACd,QAAQ;QAER,UAAU;QACV,YAAY;QACZ,SAAS;QACT,UAAU;QACV,SAAS;QACT,UAAU;QACV,UAAU;QACV,YAAY;QACZ,kBAAkB;QAClB,cAAc;QAEd,aAAa;QACb,WAAW;QACX,QAAQ;QACR,SAAS;QACT,UAAU;QACV,YAAY;QAEZ,yBAAyB;QACzB,aAAa;QACb,WAAW;QACX,gBAAgB;QAChB,uBAAuB;QACvB,kBAAkB;QAClB,eAAe;QAEf,YAAY;QACZ,YAAY;QACZ,WAAW;QACX,OAAO;QACP,UAAU;QACV,eAAe;QACf,aAAa;QACb,cAAc;QACd,sBAAsB;QACtB,WAAW;QACX,QAAQ;QACR,QAAQ;QACR,aAAa;QACb,WAAW;QACX,aAAa;QACb,YAAY;QACZ,YAAY;QACZ,SAAS;QACT,aAAa;QACb,WAAW;QACX,YAAY;QACZ,YAAY;QACZ,YAAY;KACf,CAAC;AACN,CAAC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { useCoreStore } from "./stores/core";
|
|
2
|
+
export { useNotificationsStore } from "./stores/notifications";
|
|
3
|
+
export { useStructureDataManagement } from "./composables/structureDataManagement";
|
|
4
|
+
export { useStructureRestApi } from "./composables/structureRestApi";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AAC9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAA;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ref, computed } from 'vue';
|
|
2
|
+
import { defineStore } from "pinia";
|
|
3
|
+
export const useCoreStore = defineStore('core', () => {
|
|
4
|
+
/**
|
|
5
|
+
* This loading must be accessed from anywhere.
|
|
6
|
+
* Components, guards and so on.
|
|
7
|
+
*/
|
|
8
|
+
const loadings = ref({});
|
|
9
|
+
/**
|
|
10
|
+
* Set loading value
|
|
11
|
+
*
|
|
12
|
+
* @param key
|
|
13
|
+
* @param value
|
|
14
|
+
*/
|
|
15
|
+
const setLoading = (key, value) => loadings.value[key] = value;
|
|
16
|
+
/**
|
|
17
|
+
* Reset all loadings
|
|
18
|
+
*/
|
|
19
|
+
const resetLoadings = () => loadings.value = {};
|
|
20
|
+
/**
|
|
21
|
+
* Check if there is a specific loading
|
|
22
|
+
*/
|
|
23
|
+
const getLoading = (key) => loadings.value[key];
|
|
24
|
+
/**
|
|
25
|
+
* Check if there are any loadings
|
|
26
|
+
*/
|
|
27
|
+
const isLoading = computed(() => Object.values(loadings.value).some(Boolean));
|
|
28
|
+
return {
|
|
29
|
+
loadings,
|
|
30
|
+
isLoading,
|
|
31
|
+
resetLoadings,
|
|
32
|
+
setLoading,
|
|
33
|
+
getLoading,
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=core.js.map
|