@erpp/react-api-cronos-frontend 1.0.14 → 1.0.16
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/index.d.mts +989 -6
- package/dist/index.d.ts +989 -6
- package/dist/index.js +215 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +198 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -853,7 +853,7 @@ var AdeudoAPI = class extends APIClientBase {
|
|
|
853
853
|
var AdeudoAPI_default = AdeudoAPI;
|
|
854
854
|
|
|
855
855
|
// src/infrastructure/api/utils/createApiHooks.ts
|
|
856
|
-
import { useState, useCallback
|
|
856
|
+
import { useState, useCallback as useCallback2 } from "react";
|
|
857
857
|
|
|
858
858
|
// src/infrastructure/api/utils/globalErrorLogger.ts
|
|
859
859
|
import fs from "fs";
|
|
@@ -886,6 +886,197 @@ var GlobalErrorLogger = class {
|
|
|
886
886
|
};
|
|
887
887
|
var globalErrorLogger = new GlobalErrorLogger();
|
|
888
888
|
|
|
889
|
+
// src/infrastructure/api/utils/useFetchList.ts
|
|
890
|
+
import { useCallback, useEffect, useReducer } from "react";
|
|
891
|
+
function getInitialState(params) {
|
|
892
|
+
var _a, _b, _c, _d, _e, _f;
|
|
893
|
+
return {
|
|
894
|
+
data: null,
|
|
895
|
+
error: null,
|
|
896
|
+
isFetching: false,
|
|
897
|
+
isLoading: true,
|
|
898
|
+
pagination: {
|
|
899
|
+
limit: (_b = (_a = params.params) == null ? void 0 : _a.limit) != null ? _b : 10,
|
|
900
|
+
page: (_d = (_c = params.params) == null ? void 0 : _c.page) != null ? _d : 1,
|
|
901
|
+
orderBy: (_f = (_e = params.params) == null ? void 0 : _e.orderBy) != null ? _f : ""
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
function reducer(state, action) {
|
|
906
|
+
switch (action.type) {
|
|
907
|
+
case "FETCH_START":
|
|
908
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
909
|
+
isFetching: true
|
|
910
|
+
});
|
|
911
|
+
case "FETCH_SUCCESS":
|
|
912
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
913
|
+
data: action.payload,
|
|
914
|
+
error: null,
|
|
915
|
+
isFetching: false,
|
|
916
|
+
isLoading: false
|
|
917
|
+
});
|
|
918
|
+
case "FETCH_ERROR":
|
|
919
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
920
|
+
error: action.payload,
|
|
921
|
+
isFetching: false,
|
|
922
|
+
isLoading: false
|
|
923
|
+
});
|
|
924
|
+
case "PATCH_PAGINATION_SILENT":
|
|
925
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
926
|
+
pagination: __spreadValues(__spreadValues({}, state.pagination), action.payload)
|
|
927
|
+
});
|
|
928
|
+
default:
|
|
929
|
+
return state;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
function useFetchList(client, params, config) {
|
|
933
|
+
var _a, _b, _c;
|
|
934
|
+
const [state, dispatch] = useReducer(
|
|
935
|
+
reducer,
|
|
936
|
+
getInitialState(params)
|
|
937
|
+
);
|
|
938
|
+
const { data, error, isFetching, isLoading, pagination } = state;
|
|
939
|
+
useEffect(() => {
|
|
940
|
+
var _a2, _b2, _c2, _d, _e, _f;
|
|
941
|
+
dispatch({
|
|
942
|
+
type: "PATCH_PAGINATION_SILENT",
|
|
943
|
+
payload: {
|
|
944
|
+
limit: (_b2 = (_a2 = params.params) == null ? void 0 : _a2.limit) != null ? _b2 : 10,
|
|
945
|
+
page: (_d = (_c2 = params.params) == null ? void 0 : _c2.page) != null ? _d : 1,
|
|
946
|
+
orderBy: (_f = (_e = params.params) == null ? void 0 : _e.orderBy) != null ? _f : ""
|
|
947
|
+
}
|
|
948
|
+
});
|
|
949
|
+
}, [
|
|
950
|
+
(_a = params.params) == null ? void 0 : _a.limit,
|
|
951
|
+
(_b = params.params) == null ? void 0 : _b.page,
|
|
952
|
+
(_c = params.params) == null ? void 0 : _c.orderBy
|
|
953
|
+
]);
|
|
954
|
+
const executeQuery = useCallback(
|
|
955
|
+
async (newParams) => {
|
|
956
|
+
dispatch({ type: "FETCH_START" });
|
|
957
|
+
try {
|
|
958
|
+
const result = await client.query(newParams);
|
|
959
|
+
if (result === null) {
|
|
960
|
+
throw new Error("No data returned from API");
|
|
961
|
+
}
|
|
962
|
+
dispatch({ type: "FETCH_SUCCESS", payload: result });
|
|
963
|
+
return result;
|
|
964
|
+
} catch (err) {
|
|
965
|
+
dispatch({ type: "FETCH_ERROR", payload: err });
|
|
966
|
+
globalErrorLogger.log(err, "useFetchList");
|
|
967
|
+
}
|
|
968
|
+
},
|
|
969
|
+
[client]
|
|
970
|
+
);
|
|
971
|
+
const fetchData = useCallback(async () => {
|
|
972
|
+
await executeQuery(params);
|
|
973
|
+
}, [executeQuery, JSON.stringify(params)]);
|
|
974
|
+
useEffect(() => {
|
|
975
|
+
if (config == null ? void 0 : config.fetchOnMount) {
|
|
976
|
+
fetchData();
|
|
977
|
+
}
|
|
978
|
+
}, [fetchData, config == null ? void 0 : config.fetchOnMount]);
|
|
979
|
+
const fetchPage = useCallback(
|
|
980
|
+
async (page) => {
|
|
981
|
+
if (page < 1) return;
|
|
982
|
+
await executeQuery({
|
|
983
|
+
params: __spreadProps(__spreadValues({}, params.params), {
|
|
984
|
+
page,
|
|
985
|
+
limit: pagination.limit
|
|
986
|
+
})
|
|
987
|
+
});
|
|
988
|
+
dispatch({
|
|
989
|
+
type: "PATCH_PAGINATION_SILENT",
|
|
990
|
+
payload: { page }
|
|
991
|
+
});
|
|
992
|
+
},
|
|
993
|
+
[pagination.limit, params, executeQuery]
|
|
994
|
+
);
|
|
995
|
+
const fetchLimit = useCallback(
|
|
996
|
+
async (limit) => {
|
|
997
|
+
await executeQuery({
|
|
998
|
+
params: __spreadProps(__spreadValues({}, params.params), {
|
|
999
|
+
page: 1,
|
|
1000
|
+
limit
|
|
1001
|
+
})
|
|
1002
|
+
});
|
|
1003
|
+
dispatch({
|
|
1004
|
+
type: "PATCH_PAGINATION_SILENT",
|
|
1005
|
+
payload: { limit, page: 1 }
|
|
1006
|
+
});
|
|
1007
|
+
},
|
|
1008
|
+
[params, executeQuery]
|
|
1009
|
+
);
|
|
1010
|
+
const fetchNextPage = useCallback(() => {
|
|
1011
|
+
var _a2;
|
|
1012
|
+
fetchPage(((_a2 = pagination.page) != null ? _a2 : 0) + 1);
|
|
1013
|
+
}, [fetchPage, pagination.page]);
|
|
1014
|
+
const fetchPreviousPage = useCallback(() => {
|
|
1015
|
+
var _a2;
|
|
1016
|
+
const prev = ((_a2 = pagination.page) != null ? _a2 : 1) - 1;
|
|
1017
|
+
if (prev < 1) return;
|
|
1018
|
+
fetchPage(prev);
|
|
1019
|
+
}, [fetchPage, pagination.page]);
|
|
1020
|
+
const fetchPagination = useCallback(
|
|
1021
|
+
async ({ page, limit, orderBy }) => {
|
|
1022
|
+
await executeQuery({
|
|
1023
|
+
params: __spreadProps(__spreadValues({}, params.params), {
|
|
1024
|
+
page,
|
|
1025
|
+
limit,
|
|
1026
|
+
orderBy
|
|
1027
|
+
})
|
|
1028
|
+
});
|
|
1029
|
+
dispatch({
|
|
1030
|
+
type: "PATCH_PAGINATION_SILENT",
|
|
1031
|
+
payload: { page, limit, orderBy }
|
|
1032
|
+
});
|
|
1033
|
+
},
|
|
1034
|
+
[params, executeQuery]
|
|
1035
|
+
);
|
|
1036
|
+
return {
|
|
1037
|
+
/**
|
|
1038
|
+
* @description Datos obtenidos de la API
|
|
1039
|
+
*/
|
|
1040
|
+
data,
|
|
1041
|
+
error,
|
|
1042
|
+
isFetching,
|
|
1043
|
+
isLoading,
|
|
1044
|
+
/**
|
|
1045
|
+
* @description Información de paginación actual
|
|
1046
|
+
*/
|
|
1047
|
+
pagination,
|
|
1048
|
+
refetch: fetchData,
|
|
1049
|
+
/**
|
|
1050
|
+
* @description Obtener una página específica
|
|
1051
|
+
*/
|
|
1052
|
+
fetchPage,
|
|
1053
|
+
/**
|
|
1054
|
+
* @description Obtener siguiente página
|
|
1055
|
+
*/
|
|
1056
|
+
fetchNextPage,
|
|
1057
|
+
/**
|
|
1058
|
+
* @description Obtener la página anterior
|
|
1059
|
+
*/
|
|
1060
|
+
fetchPreviousPage,
|
|
1061
|
+
/**
|
|
1062
|
+
* @description Establecer el límite de elementos por página
|
|
1063
|
+
*/
|
|
1064
|
+
fetchLimit,
|
|
1065
|
+
/**
|
|
1066
|
+
* @description Obtener página, límite y orden en una sola llamada
|
|
1067
|
+
*/
|
|
1068
|
+
fetchPagination
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
var createUseFetchList = (client) => {
|
|
1072
|
+
const setupUseFetchList = (params, config) => useFetchList(
|
|
1073
|
+
client,
|
|
1074
|
+
params,
|
|
1075
|
+
config
|
|
1076
|
+
);
|
|
1077
|
+
return setupUseFetchList;
|
|
1078
|
+
};
|
|
1079
|
+
|
|
889
1080
|
// src/infrastructure/api/utils/createApiHooks.ts
|
|
890
1081
|
function createApiHooksBase(client) {
|
|
891
1082
|
function useFetchById(params) {
|
|
@@ -893,7 +1084,7 @@ function createApiHooksBase(client) {
|
|
|
893
1084
|
const [error, setError] = useState(null);
|
|
894
1085
|
const [isFetching, setIsFetching] = useState(false);
|
|
895
1086
|
const [isLoading, setIsLoading] = useState(true);
|
|
896
|
-
const fetchData =
|
|
1087
|
+
const fetchData = useCallback2(async () => {
|
|
897
1088
|
setIsFetching(true);
|
|
898
1089
|
try {
|
|
899
1090
|
const result = await client.getById(params);
|
|
@@ -909,37 +1100,11 @@ function createApiHooksBase(client) {
|
|
|
909
1100
|
}, [JSON.stringify(params)]);
|
|
910
1101
|
return { data, error, isFetching, isLoading, refetch: fetchData };
|
|
911
1102
|
}
|
|
912
|
-
function useFetchList(params, config) {
|
|
913
|
-
const [data, setData] = useState(null);
|
|
914
|
-
const [error, setError] = useState(null);
|
|
915
|
-
const [isFetching, setIsFetching] = useState(false);
|
|
916
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
917
|
-
const fetchData = useCallback(async () => {
|
|
918
|
-
setIsFetching(true);
|
|
919
|
-
try {
|
|
920
|
-
const result = await client.query(params);
|
|
921
|
-
setData(result);
|
|
922
|
-
setError(null);
|
|
923
|
-
} catch (err) {
|
|
924
|
-
setError(err);
|
|
925
|
-
globalErrorLogger.log(err, "useFetchList");
|
|
926
|
-
} finally {
|
|
927
|
-
setIsFetching(false);
|
|
928
|
-
setIsLoading(false);
|
|
929
|
-
}
|
|
930
|
-
}, [JSON.stringify(params)]);
|
|
931
|
-
useEffect(function() {
|
|
932
|
-
if ((config == null ? void 0 : config.fetchOnMount) === true) {
|
|
933
|
-
fetchData();
|
|
934
|
-
}
|
|
935
|
-
}, [fetchData, config == null ? void 0 : config.fetchOnMount]);
|
|
936
|
-
return { data, error, isFetching, isLoading, refetch: fetchData };
|
|
937
|
-
}
|
|
938
1103
|
function useCreate() {
|
|
939
1104
|
const [isLoading, setIsLoading] = useState(false);
|
|
940
1105
|
const [error, setError] = useState(null);
|
|
941
1106
|
const [data, setData] = useState(null);
|
|
942
|
-
const mutate =
|
|
1107
|
+
const mutate = useCallback2(async (params) => {
|
|
943
1108
|
setIsLoading(true);
|
|
944
1109
|
try {
|
|
945
1110
|
const result = await client.create(params);
|
|
@@ -960,7 +1125,7 @@ function createApiHooksBase(client) {
|
|
|
960
1125
|
const [isLoading, setIsLoading] = useState(false);
|
|
961
1126
|
const [error, setError] = useState(null);
|
|
962
1127
|
const [data, setData] = useState(null);
|
|
963
|
-
const mutate =
|
|
1128
|
+
const mutate = useCallback2(async (params) => {
|
|
964
1129
|
setIsLoading(true);
|
|
965
1130
|
try {
|
|
966
1131
|
const result = await client.update(params);
|
|
@@ -981,7 +1146,7 @@ function createApiHooksBase(client) {
|
|
|
981
1146
|
const [isLoading, setIsLoading] = useState(false);
|
|
982
1147
|
const [error, setError] = useState(null);
|
|
983
1148
|
const [success, setSuccess] = useState(false);
|
|
984
|
-
const mutate =
|
|
1149
|
+
const mutate = useCallback2(async (params) => {
|
|
985
1150
|
setIsLoading(true);
|
|
986
1151
|
try {
|
|
987
1152
|
const result = await client.delete(params);
|
|
@@ -1003,7 +1168,7 @@ function createApiHooksBase(client) {
|
|
|
1003
1168
|
const [error, setError] = useState(null);
|
|
1004
1169
|
const [isFetching, setIsFetching] = useState(false);
|
|
1005
1170
|
const [isLoading, setIsLoading] = useState(true);
|
|
1006
|
-
const fetchData =
|
|
1171
|
+
const fetchData = useCallback2(async () => {
|
|
1007
1172
|
setIsFetching(true);
|
|
1008
1173
|
try {
|
|
1009
1174
|
const result = await client.filterMatch(params);
|
|
@@ -1021,7 +1186,7 @@ function createApiHooksBase(client) {
|
|
|
1021
1186
|
}
|
|
1022
1187
|
return {
|
|
1023
1188
|
useFetchById,
|
|
1024
|
-
useFetchList,
|
|
1189
|
+
useFetchList: createUseFetchList(client),
|
|
1025
1190
|
useCreate,
|
|
1026
1191
|
useUpdate,
|
|
1027
1192
|
useDelete,
|