@fto-consult/expo-ui 6.67.9 → 6.67.10
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/package.json +2 -2
- package/src/context/query.js +0 -92
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fto-consult/expo-ui",
|
3
|
-
"version": "6.67.
|
3
|
+
"version": "6.67.10",
|
4
4
|
"description": "Bibliothèque de composants UI Expo,react-native",
|
5
5
|
"main": "main",
|
6
6
|
"scripts": {
|
@@ -71,7 +71,7 @@
|
|
71
71
|
"@expo/html-elements": "^0.5.1",
|
72
72
|
"@expo/vector-icons": "^13.0.0",
|
73
73
|
"@faker-js/faker": "^8.0.2",
|
74
|
-
"@fto-consult/common": "^3.57.
|
74
|
+
"@fto-consult/common": "^3.57.7",
|
75
75
|
"@pchmn/expo-material3-theme": "^1.3.1",
|
76
76
|
"@react-native-async-storage/async-storage": "1.18.2",
|
77
77
|
"@react-native-community/datetimepicker": "7.2.0",
|
package/src/context/query.js
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
import {isNonNullString,isObj,extendObj} from "$cutils";
|
2
|
-
import { useQuery as useRQuery, useMutation as RQUseMutation, useQueryClient } from "@tanstack/react-query";
|
3
|
-
import { getFetcherOptions as apiGetFetcherOptions } from '$capi';
|
4
|
-
|
5
|
-
export const RETRY_OPTIONS = { cacheTime: 2000,refetchInterval:5000};
|
6
|
-
|
7
|
-
export const RETRY_LIST_OPTIONS = {cacheTime:5000,refetchInterval:20000};
|
8
|
-
|
9
|
-
const isValidNetworkMode = (nMode)=>isNonNullString(nMode) && ['online','always','offlineFirst'].includes(nMode.toLowerCase().trim());
|
10
|
-
const isValidRetryDelay = (retryDelay) => typeof retryDelay =='number' || typeof retryDelay ==='function'? true : false;
|
11
|
-
|
12
|
-
const queries403Cached = {};
|
13
|
-
|
14
|
-
/***** override of useQuery
|
15
|
-
@see : https://tanstack.com/query/v4/docs/react/guides/migrating-to-react-query-4
|
16
|
-
@see : https://tanstack.com/query/v4/docs/react/reference/useQuery for useQuery options
|
17
|
-
@param {boolean} handle403, pour la prise en compte du 403
|
18
|
-
@param {Array} key, array of key string, The query key to use for this query.The query key will be hashed into a stable hash. See Query Keys for more information. The query will automatically update when this key changes (as long as enabled is not set to false).
|
19
|
-
@param {function} queryFn, query function (context: QueryFunctionContext) => Promise<TData>
|
20
|
-
@param {boolean} enabled Set this to false to disable this query from automatically running.
|
21
|
-
@param {string} networkMode 'online' | 'always' | 'offlineFirst
|
22
|
-
@param {boolean| number | (failureCount: number, error: TError) => boolean} retry If false, failed queries will not retry by default.If true, failed queries will retry infinitely. If set to a number, e.g. 3, failed queries will retry until the failed query count meets that number.
|
23
|
-
@param {boolean} retryOnMount If set to false, the query will not be retried on mount if it contains an error. Defaults to true.
|
24
|
-
@param {number | (retryAttempt: number, error: TError) => number} retryDelay This function receives a retryAttempt integer and the actual Error and returns the delay to apply before he next attempt in milliseconds. A function like attempt => Math.min(attempt > 1 ? 2 ** attempt * 1000 : 1000, 30 * 1000) applies exponential backoff., A function like attempt => attempt * 1000 applies linear backoff.
|
25
|
-
*/
|
26
|
-
export const useQuery = (key,queryFn,enabled,networkMode,retry,retryOnMount,retryDelay,...args)=>{
|
27
|
-
const options = isObj(key)? Object.assign({},key) : isNonNullString(key)? {queryKey:key.split(",")} : Array.isArray(key)? {queryKey:key} : {};
|
28
|
-
key = isNonNullString(key)? key.split(",") : Array.isArray(key)? key : [];
|
29
|
-
options.queryKey = Array.isArray(options.queryKey) && options.queryKey.length && options.queryKey || key;
|
30
|
-
options.queryFn = typeof queryFn =='function' ? queryFn : typeof options.queryFn =='function'? options.queryFn : undefined;
|
31
|
-
options.enabled = typeof enabled === "boolean" ? enabled : typeof options.enabled =='boolean' ? options.enabled : true;
|
32
|
-
options.networkMode = isValidNetworkMode(networkMode) ? networkMode.toLowerCase().trim() : isValidNetworkMode(options.networkMode) ? options.networkMode.toLowerCase().trim() : "online";
|
33
|
-
options.retry = typeof retry =='boolean' || typeof retry ==='number' ? retry : typeof options.retry ==='boolean' || typeof options.retry =='number' ? options.retry : undefined;
|
34
|
-
options.retryOnMount = typeof retryOnMount ==='boolean'? retryOnMount : typeof options.retryOnMount =='boolean' ? options.retryOnMount : undefined;
|
35
|
-
options.retryDelay = isValidRetryDelay(retryDelay)? retryDelay : isValidRetryDelay(options.retryDelay) ? options.retryDelay : undefined;
|
36
|
-
[queryFn,enabled,networkMode,retry,retryOnMount,retryDelay].map((a)=>{
|
37
|
-
isObj(a) && extendObj(true,options,a);
|
38
|
-
});
|
39
|
-
args.map((a)=>{
|
40
|
-
isObj(a) && extendObj(true,options,a);
|
41
|
-
});
|
42
|
-
options.enabled = !options.queryKey?.length ? false : options.enabled;
|
43
|
-
//if not enabled, we have to disabled retry option
|
44
|
-
options.retry = !options.enabled ? false : options.retry;
|
45
|
-
const {onError} = options;
|
46
|
-
const keyString = key.join(",");
|
47
|
-
if(keyString && queries403Cached[keyString]){
|
48
|
-
options.retry = false;
|
49
|
-
}
|
50
|
-
const {handle403} = options;
|
51
|
-
delete options.handle403;
|
52
|
-
options.onError = (e,...args)=>{
|
53
|
-
if(handle403){
|
54
|
-
const {response} = isObj(e)? e : {};
|
55
|
-
if(isObj(response) && response.status === 403){
|
56
|
-
keyString ? queries403Cached[keyString] = true : null;
|
57
|
-
setTimeout(()=>{
|
58
|
-
keyString && delete queries403Cached[keyString];
|
59
|
-
},100);
|
60
|
-
}
|
61
|
-
}
|
62
|
-
if(typeof onError ==='function' && (onError(e,options) === false)) return;
|
63
|
-
}
|
64
|
-
//const r = !options.enabled ? console.error("unable to get query for options",options) : null;
|
65
|
-
return useRQuery(options);
|
66
|
-
}
|
67
|
-
|
68
|
-
/****
|
69
|
-
@see : https://tanstack.com/query/v4/docs/react/reference/useMutation
|
70
|
-
*/
|
71
|
-
export const useMutation = (mutationFn,cacheTime,mutationKey,...args)=>{
|
72
|
-
const options = isObj(mutationFn)? Object.assign({},mutationFn) : typeof(mutationFn) =='function'? {mutationFn} : {};
|
73
|
-
mutationFn = typeof mutationFn ==='function' ? mutationFn : undefined;
|
74
|
-
mutationFn = mutationFn || typeof options.mutationFn == 'function' ? options.mutationFn : undefined;
|
75
|
-
options.cacheTime = typeof cacheTime =='number' ? cacheTime : typeof options.cacheTime =='number'? options.cacheTime : undefined;
|
76
|
-
options.mutationKey = isNonNullString(mutationKey) && mutationKey || isNonNullString(options.mutationKey) ? options.mutationKey : undefined;
|
77
|
-
[cacheTime,mutationKey].map((a)=>{
|
78
|
-
isObj(a) && extendObj(true,options,a);
|
79
|
-
});
|
80
|
-
args.map((a)=>{
|
81
|
-
isObj(a) && extendObj(true,options,a);
|
82
|
-
});
|
83
|
-
options.mutationFn = async (params,...rest) => {
|
84
|
-
return await mutationFn(params,...rest);
|
85
|
-
}
|
86
|
-
return RQUseMutation(options);
|
87
|
-
}
|
88
|
-
|
89
|
-
|
90
|
-
export const getFetcherOptions = (path,opts)=>{
|
91
|
-
return apiGetFetcherOptions(path,opts);
|
92
|
-
}
|