@erpp/react-api-cronos-frontend 1.0.15 → 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 +983 -6
- package/dist/index.d.ts +983 -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.js
CHANGED
|
@@ -1370,7 +1370,7 @@ var AdeudoAPI = class extends APIClientBase {
|
|
|
1370
1370
|
var AdeudoAPI_default = AdeudoAPI;
|
|
1371
1371
|
|
|
1372
1372
|
// src/infrastructure/api/utils/createApiHooks.ts
|
|
1373
|
-
var
|
|
1373
|
+
var import_react2 = require("react");
|
|
1374
1374
|
|
|
1375
1375
|
// src/infrastructure/api/utils/globalErrorLogger.ts
|
|
1376
1376
|
var import_fs = __toESM(require("fs"));
|
|
@@ -1403,14 +1403,205 @@ var GlobalErrorLogger = class {
|
|
|
1403
1403
|
};
|
|
1404
1404
|
var globalErrorLogger = new GlobalErrorLogger();
|
|
1405
1405
|
|
|
1406
|
+
// src/infrastructure/api/utils/useFetchList.ts
|
|
1407
|
+
var import_react = require("react");
|
|
1408
|
+
function getInitialState(params) {
|
|
1409
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1410
|
+
return {
|
|
1411
|
+
data: null,
|
|
1412
|
+
error: null,
|
|
1413
|
+
isFetching: false,
|
|
1414
|
+
isLoading: true,
|
|
1415
|
+
pagination: {
|
|
1416
|
+
limit: (_b = (_a = params.params) == null ? void 0 : _a.limit) != null ? _b : 10,
|
|
1417
|
+
page: (_d = (_c = params.params) == null ? void 0 : _c.page) != null ? _d : 1,
|
|
1418
|
+
orderBy: (_f = (_e = params.params) == null ? void 0 : _e.orderBy) != null ? _f : ""
|
|
1419
|
+
}
|
|
1420
|
+
};
|
|
1421
|
+
}
|
|
1422
|
+
function reducer(state, action) {
|
|
1423
|
+
switch (action.type) {
|
|
1424
|
+
case "FETCH_START":
|
|
1425
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
1426
|
+
isFetching: true
|
|
1427
|
+
});
|
|
1428
|
+
case "FETCH_SUCCESS":
|
|
1429
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
1430
|
+
data: action.payload,
|
|
1431
|
+
error: null,
|
|
1432
|
+
isFetching: false,
|
|
1433
|
+
isLoading: false
|
|
1434
|
+
});
|
|
1435
|
+
case "FETCH_ERROR":
|
|
1436
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
1437
|
+
error: action.payload,
|
|
1438
|
+
isFetching: false,
|
|
1439
|
+
isLoading: false
|
|
1440
|
+
});
|
|
1441
|
+
case "PATCH_PAGINATION_SILENT":
|
|
1442
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
1443
|
+
pagination: __spreadValues(__spreadValues({}, state.pagination), action.payload)
|
|
1444
|
+
});
|
|
1445
|
+
default:
|
|
1446
|
+
return state;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
function useFetchList(client, params, config) {
|
|
1450
|
+
var _a, _b, _c;
|
|
1451
|
+
const [state, dispatch] = (0, import_react.useReducer)(
|
|
1452
|
+
reducer,
|
|
1453
|
+
getInitialState(params)
|
|
1454
|
+
);
|
|
1455
|
+
const { data, error, isFetching, isLoading, pagination } = state;
|
|
1456
|
+
(0, import_react.useEffect)(() => {
|
|
1457
|
+
var _a2, _b2, _c2, _d, _e, _f;
|
|
1458
|
+
dispatch({
|
|
1459
|
+
type: "PATCH_PAGINATION_SILENT",
|
|
1460
|
+
payload: {
|
|
1461
|
+
limit: (_b2 = (_a2 = params.params) == null ? void 0 : _a2.limit) != null ? _b2 : 10,
|
|
1462
|
+
page: (_d = (_c2 = params.params) == null ? void 0 : _c2.page) != null ? _d : 1,
|
|
1463
|
+
orderBy: (_f = (_e = params.params) == null ? void 0 : _e.orderBy) != null ? _f : ""
|
|
1464
|
+
}
|
|
1465
|
+
});
|
|
1466
|
+
}, [
|
|
1467
|
+
(_a = params.params) == null ? void 0 : _a.limit,
|
|
1468
|
+
(_b = params.params) == null ? void 0 : _b.page,
|
|
1469
|
+
(_c = params.params) == null ? void 0 : _c.orderBy
|
|
1470
|
+
]);
|
|
1471
|
+
const executeQuery = (0, import_react.useCallback)(
|
|
1472
|
+
async (newParams) => {
|
|
1473
|
+
dispatch({ type: "FETCH_START" });
|
|
1474
|
+
try {
|
|
1475
|
+
const result = await client.query(newParams);
|
|
1476
|
+
if (result === null) {
|
|
1477
|
+
throw new Error("No data returned from API");
|
|
1478
|
+
}
|
|
1479
|
+
dispatch({ type: "FETCH_SUCCESS", payload: result });
|
|
1480
|
+
return result;
|
|
1481
|
+
} catch (err) {
|
|
1482
|
+
dispatch({ type: "FETCH_ERROR", payload: err });
|
|
1483
|
+
globalErrorLogger.log(err, "useFetchList");
|
|
1484
|
+
}
|
|
1485
|
+
},
|
|
1486
|
+
[client]
|
|
1487
|
+
);
|
|
1488
|
+
const fetchData = (0, import_react.useCallback)(async () => {
|
|
1489
|
+
await executeQuery(params);
|
|
1490
|
+
}, [executeQuery, JSON.stringify(params)]);
|
|
1491
|
+
(0, import_react.useEffect)(() => {
|
|
1492
|
+
if (config == null ? void 0 : config.fetchOnMount) {
|
|
1493
|
+
fetchData();
|
|
1494
|
+
}
|
|
1495
|
+
}, [fetchData, config == null ? void 0 : config.fetchOnMount]);
|
|
1496
|
+
const fetchPage = (0, import_react.useCallback)(
|
|
1497
|
+
async (page) => {
|
|
1498
|
+
if (page < 1) return;
|
|
1499
|
+
await executeQuery({
|
|
1500
|
+
params: __spreadProps(__spreadValues({}, params.params), {
|
|
1501
|
+
page,
|
|
1502
|
+
limit: pagination.limit
|
|
1503
|
+
})
|
|
1504
|
+
});
|
|
1505
|
+
dispatch({
|
|
1506
|
+
type: "PATCH_PAGINATION_SILENT",
|
|
1507
|
+
payload: { page }
|
|
1508
|
+
});
|
|
1509
|
+
},
|
|
1510
|
+
[pagination.limit, params, executeQuery]
|
|
1511
|
+
);
|
|
1512
|
+
const fetchLimit = (0, import_react.useCallback)(
|
|
1513
|
+
async (limit) => {
|
|
1514
|
+
await executeQuery({
|
|
1515
|
+
params: __spreadProps(__spreadValues({}, params.params), {
|
|
1516
|
+
page: 1,
|
|
1517
|
+
limit
|
|
1518
|
+
})
|
|
1519
|
+
});
|
|
1520
|
+
dispatch({
|
|
1521
|
+
type: "PATCH_PAGINATION_SILENT",
|
|
1522
|
+
payload: { limit, page: 1 }
|
|
1523
|
+
});
|
|
1524
|
+
},
|
|
1525
|
+
[params, executeQuery]
|
|
1526
|
+
);
|
|
1527
|
+
const fetchNextPage = (0, import_react.useCallback)(() => {
|
|
1528
|
+
var _a2;
|
|
1529
|
+
fetchPage(((_a2 = pagination.page) != null ? _a2 : 0) + 1);
|
|
1530
|
+
}, [fetchPage, pagination.page]);
|
|
1531
|
+
const fetchPreviousPage = (0, import_react.useCallback)(() => {
|
|
1532
|
+
var _a2;
|
|
1533
|
+
const prev = ((_a2 = pagination.page) != null ? _a2 : 1) - 1;
|
|
1534
|
+
if (prev < 1) return;
|
|
1535
|
+
fetchPage(prev);
|
|
1536
|
+
}, [fetchPage, pagination.page]);
|
|
1537
|
+
const fetchPagination = (0, import_react.useCallback)(
|
|
1538
|
+
async ({ page, limit, orderBy }) => {
|
|
1539
|
+
await executeQuery({
|
|
1540
|
+
params: __spreadProps(__spreadValues({}, params.params), {
|
|
1541
|
+
page,
|
|
1542
|
+
limit,
|
|
1543
|
+
orderBy
|
|
1544
|
+
})
|
|
1545
|
+
});
|
|
1546
|
+
dispatch({
|
|
1547
|
+
type: "PATCH_PAGINATION_SILENT",
|
|
1548
|
+
payload: { page, limit, orderBy }
|
|
1549
|
+
});
|
|
1550
|
+
},
|
|
1551
|
+
[params, executeQuery]
|
|
1552
|
+
);
|
|
1553
|
+
return {
|
|
1554
|
+
/**
|
|
1555
|
+
* @description Datos obtenidos de la API
|
|
1556
|
+
*/
|
|
1557
|
+
data,
|
|
1558
|
+
error,
|
|
1559
|
+
isFetching,
|
|
1560
|
+
isLoading,
|
|
1561
|
+
/**
|
|
1562
|
+
* @description Información de paginación actual
|
|
1563
|
+
*/
|
|
1564
|
+
pagination,
|
|
1565
|
+
refetch: fetchData,
|
|
1566
|
+
/**
|
|
1567
|
+
* @description Obtener una página específica
|
|
1568
|
+
*/
|
|
1569
|
+
fetchPage,
|
|
1570
|
+
/**
|
|
1571
|
+
* @description Obtener siguiente página
|
|
1572
|
+
*/
|
|
1573
|
+
fetchNextPage,
|
|
1574
|
+
/**
|
|
1575
|
+
* @description Obtener la página anterior
|
|
1576
|
+
*/
|
|
1577
|
+
fetchPreviousPage,
|
|
1578
|
+
/**
|
|
1579
|
+
* @description Establecer el límite de elementos por página
|
|
1580
|
+
*/
|
|
1581
|
+
fetchLimit,
|
|
1582
|
+
/**
|
|
1583
|
+
* @description Obtener página, límite y orden en una sola llamada
|
|
1584
|
+
*/
|
|
1585
|
+
fetchPagination
|
|
1586
|
+
};
|
|
1587
|
+
}
|
|
1588
|
+
var createUseFetchList = (client) => {
|
|
1589
|
+
const setupUseFetchList = (params, config) => useFetchList(
|
|
1590
|
+
client,
|
|
1591
|
+
params,
|
|
1592
|
+
config
|
|
1593
|
+
);
|
|
1594
|
+
return setupUseFetchList;
|
|
1595
|
+
};
|
|
1596
|
+
|
|
1406
1597
|
// src/infrastructure/api/utils/createApiHooks.ts
|
|
1407
1598
|
function createApiHooksBase(client) {
|
|
1408
1599
|
function useFetchById(params) {
|
|
1409
|
-
const [data, setData] = (0,
|
|
1410
|
-
const [error, setError] = (0,
|
|
1411
|
-
const [isFetching, setIsFetching] = (0,
|
|
1412
|
-
const [isLoading, setIsLoading] = (0,
|
|
1413
|
-
const fetchData = (0,
|
|
1600
|
+
const [data, setData] = (0, import_react2.useState)(null);
|
|
1601
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
1602
|
+
const [isFetching, setIsFetching] = (0, import_react2.useState)(false);
|
|
1603
|
+
const [isLoading, setIsLoading] = (0, import_react2.useState)(true);
|
|
1604
|
+
const fetchData = (0, import_react2.useCallback)(async () => {
|
|
1414
1605
|
setIsFetching(true);
|
|
1415
1606
|
try {
|
|
1416
1607
|
const result = await client.getById(params);
|
|
@@ -1426,37 +1617,11 @@ function createApiHooksBase(client) {
|
|
|
1426
1617
|
}, [JSON.stringify(params)]);
|
|
1427
1618
|
return { data, error, isFetching, isLoading, refetch: fetchData };
|
|
1428
1619
|
}
|
|
1429
|
-
function useFetchList(params, config) {
|
|
1430
|
-
const [data, setData] = (0, import_react.useState)(null);
|
|
1431
|
-
const [error, setError] = (0, import_react.useState)(null);
|
|
1432
|
-
const [isFetching, setIsFetching] = (0, import_react.useState)(false);
|
|
1433
|
-
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
1434
|
-
const fetchData = (0, import_react.useCallback)(async () => {
|
|
1435
|
-
setIsFetching(true);
|
|
1436
|
-
try {
|
|
1437
|
-
const result = await client.query(params);
|
|
1438
|
-
setData(result);
|
|
1439
|
-
setError(null);
|
|
1440
|
-
} catch (err) {
|
|
1441
|
-
setError(err);
|
|
1442
|
-
globalErrorLogger.log(err, "useFetchList");
|
|
1443
|
-
} finally {
|
|
1444
|
-
setIsFetching(false);
|
|
1445
|
-
setIsLoading(false);
|
|
1446
|
-
}
|
|
1447
|
-
}, [JSON.stringify(params)]);
|
|
1448
|
-
(0, import_react.useEffect)(function() {
|
|
1449
|
-
if ((config == null ? void 0 : config.fetchOnMount) === true) {
|
|
1450
|
-
fetchData();
|
|
1451
|
-
}
|
|
1452
|
-
}, [fetchData, config == null ? void 0 : config.fetchOnMount]);
|
|
1453
|
-
return { data, error, isFetching, isLoading, refetch: fetchData };
|
|
1454
|
-
}
|
|
1455
1620
|
function useCreate() {
|
|
1456
|
-
const [isLoading, setIsLoading] = (0,
|
|
1457
|
-
const [error, setError] = (0,
|
|
1458
|
-
const [data, setData] = (0,
|
|
1459
|
-
const mutate = (0,
|
|
1621
|
+
const [isLoading, setIsLoading] = (0, import_react2.useState)(false);
|
|
1622
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
1623
|
+
const [data, setData] = (0, import_react2.useState)(null);
|
|
1624
|
+
const mutate = (0, import_react2.useCallback)(async (params) => {
|
|
1460
1625
|
setIsLoading(true);
|
|
1461
1626
|
try {
|
|
1462
1627
|
const result = await client.create(params);
|
|
@@ -1474,10 +1639,10 @@ function createApiHooksBase(client) {
|
|
|
1474
1639
|
return { mutate, isLoading, error, data };
|
|
1475
1640
|
}
|
|
1476
1641
|
function useUpdate() {
|
|
1477
|
-
const [isLoading, setIsLoading] = (0,
|
|
1478
|
-
const [error, setError] = (0,
|
|
1479
|
-
const [data, setData] = (0,
|
|
1480
|
-
const mutate = (0,
|
|
1642
|
+
const [isLoading, setIsLoading] = (0, import_react2.useState)(false);
|
|
1643
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
1644
|
+
const [data, setData] = (0, import_react2.useState)(null);
|
|
1645
|
+
const mutate = (0, import_react2.useCallback)(async (params) => {
|
|
1481
1646
|
setIsLoading(true);
|
|
1482
1647
|
try {
|
|
1483
1648
|
const result = await client.update(params);
|
|
@@ -1495,10 +1660,10 @@ function createApiHooksBase(client) {
|
|
|
1495
1660
|
return { mutate, isLoading, error, data };
|
|
1496
1661
|
}
|
|
1497
1662
|
function useDelete() {
|
|
1498
|
-
const [isLoading, setIsLoading] = (0,
|
|
1499
|
-
const [error, setError] = (0,
|
|
1500
|
-
const [success, setSuccess] = (0,
|
|
1501
|
-
const mutate = (0,
|
|
1663
|
+
const [isLoading, setIsLoading] = (0, import_react2.useState)(false);
|
|
1664
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
1665
|
+
const [success, setSuccess] = (0, import_react2.useState)(false);
|
|
1666
|
+
const mutate = (0, import_react2.useCallback)(async (params) => {
|
|
1502
1667
|
setIsLoading(true);
|
|
1503
1668
|
try {
|
|
1504
1669
|
const result = await client.delete(params);
|
|
@@ -1516,11 +1681,11 @@ function createApiHooksBase(client) {
|
|
|
1516
1681
|
return { mutate, isLoading, error, success };
|
|
1517
1682
|
}
|
|
1518
1683
|
function useFilterMatch(params) {
|
|
1519
|
-
const [data, setData] = (0,
|
|
1520
|
-
const [error, setError] = (0,
|
|
1521
|
-
const [isFetching, setIsFetching] = (0,
|
|
1522
|
-
const [isLoading, setIsLoading] = (0,
|
|
1523
|
-
const fetchData = (0,
|
|
1684
|
+
const [data, setData] = (0, import_react2.useState)(null);
|
|
1685
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
1686
|
+
const [isFetching, setIsFetching] = (0, import_react2.useState)(false);
|
|
1687
|
+
const [isLoading, setIsLoading] = (0, import_react2.useState)(true);
|
|
1688
|
+
const fetchData = (0, import_react2.useCallback)(async () => {
|
|
1524
1689
|
setIsFetching(true);
|
|
1525
1690
|
try {
|
|
1526
1691
|
const result = await client.filterMatch(params);
|
|
@@ -1538,7 +1703,7 @@ function createApiHooksBase(client) {
|
|
|
1538
1703
|
}
|
|
1539
1704
|
return {
|
|
1540
1705
|
useFetchById,
|
|
1541
|
-
useFetchList,
|
|
1706
|
+
useFetchList: createUseFetchList(client),
|
|
1542
1707
|
useCreate,
|
|
1543
1708
|
useUpdate,
|
|
1544
1709
|
useDelete,
|