react-ecosistema-unp 1.5.2-pre.1 → 1.5.2-pre.2

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.
@@ -1,97 +1,97 @@
1
- import { useState as g, useEffect as U } from "react";
1
+ import { useState as g, useEffect as F } from "react";
2
2
  import { y as p } from "../../index-BUe3EJDH.js";
3
- const W = ({
4
- endpoint: n,
5
- localJsonPath: i,
3
+ const z = ({
4
+ endpoint: l,
5
+ localJsonPath: f,
6
6
  label: j,
7
- dependencia: l = null,
8
- queryParamKey: u,
7
+ dependencia: u = null,
8
+ queryParamKey: h,
9
9
  all: v = !1,
10
- filtrarResultados: f,
11
- selectorDatos: A,
12
- timeout: x = !1,
13
- timeoutMs: D = 25e3,
10
+ filtrarResultados: a,
11
+ selectorDatos: x,
12
+ timeout: D = !1,
13
+ timeoutMs: I = 25e3,
14
14
  // 25 segundos por defecto.
15
- id: w = null,
16
- transformarResultado: d,
15
+ id: $ = null,
16
+ transformarResultado: c,
17
17
  dataInResultsValue: T = !0
18
18
  }) => {
19
- const [I, c] = g([]), [k, E] = g(!0), [y, h] = g(null), t = j || n.replace(/\/$/, "").split("/").pop() || "datos";
20
- return U(() => {
21
- if (!v && l === null && u) {
22
- c([]), E(!1);
19
+ const [k, w] = g([]), [y, b] = g(!0), [H, E] = g(null), s = j || l.replace(/\/$/, "").split("/").pop() || "datos";
20
+ return F(() => {
21
+ if (!v && u === null && h) {
22
+ w([]), b(!1);
23
23
  return;
24
24
  }
25
- const H = async () => {
26
- E(!0), h(null);
27
- let e = n;
28
- if (w != null)
29
- e = `${n.replace(/\/$/, "")}/${w}/`;
30
- else if (l != null && u) {
31
- const r = n.includes("?") ? "&" : "?";
32
- e = `${n}${r}${u}=${l}`;
25
+ const C = async () => {
26
+ b(!0), E(null);
27
+ let e = l;
28
+ if ($ != null)
29
+ e = `${l.replace(/\/$/, "")}/${$}/`;
30
+ else if (u != null && h) {
31
+ const o = l.includes("?") ? "&" : "?";
32
+ e = `${l}${o}${h}=${u}`;
33
33
  }
34
- let o = e, a = [];
34
+ let r = e, n = [];
35
35
  try {
36
36
  if (T)
37
- for (; o; ) {
38
- let r;
39
- if (x ? r = await m(o, D) : r = await fetch(o), r.ok) {
40
- const s = await r.json(), $ = A || ((L) => L.results || []), C = f ? $(s).filter(f) : $(s);
41
- a = a.concat(C), o = s.next, c(a);
37
+ for (; r; ) {
38
+ let o;
39
+ if (D ? o = await A(r, I) : o = await fetch(r), o.ok) {
40
+ const t = await o.json(), i = x || ((U) => U.results || []), L = a ? c ? c(i(t).filter(a)) : i(t).filter(a) : c ? c(i(t)) : i(t);
41
+ n = n.concat(L), r = t.next, w(n);
42
42
  } else {
43
- console.warn(`Error HTTP (${r.status}). Intentando cargar ${t} desde archivo local...`), await b();
43
+ console.warn(`Error HTTP (${o.status}). Intentando cargar ${s} desde archivo local...`), await d();
44
44
  return;
45
45
  }
46
- console.log(`Cargando ${t} desde API...`);
46
+ console.log(`Cargando ${s} desde API...`);
47
47
  }
48
48
  else {
49
- const r = await m(e, 5e3);
50
- if (r.ok) {
51
- const s = await r.json(), $ = d ? d(s) : s;
52
- c($);
49
+ const o = await A(e, 5e3);
50
+ if (o.ok) {
51
+ const t = await o.json(), i = c ? c(t) : t;
52
+ w(i);
53
53
  } else
54
- console.warn(`Error HTTP (${r.status}). Cargando ${t} desde archivo local...`), await b();
54
+ console.warn(`Error HTTP (${o.status}). Cargando ${s} desde archivo local...`), await d();
55
55
  }
56
56
  } catch {
57
- console.warn(`Excepción al cargar desde API. Intentando cargar ${t} desde archivo local...`), await b();
57
+ console.warn(`Excepción al cargar desde API. Intentando cargar ${s} desde archivo local...`), await d();
58
58
  } finally {
59
- E(!1);
59
+ b(!1);
60
60
  }
61
- }, b = async () => {
62
- if (i)
61
+ }, d = async () => {
62
+ if (f)
63
63
  try {
64
64
  if (T) {
65
- const e = await fetch(i);
65
+ const e = await fetch(f);
66
66
  if (e.ok) {
67
- const o = await e.json(), a = f ? o.results.filter(f) : o.results;
68
- c(a);
67
+ const r = await e.json(), n = a ? c ? c(r.results.filter(a)) : r.results.filter(a) : c ? c(r.results) : r.results;
68
+ w(n);
69
69
  } else
70
- p.error(`Hubo un problema al obtener ${t} desde el archivo local.`), h(`Error al obtener ${t} desde el archivo local`);
70
+ p.error(`Hubo un problema al obtener ${s} desde el archivo local.`), E(`Error al obtener ${s} desde el archivo local`);
71
71
  } else {
72
- const e = await fetch(i);
72
+ const e = await fetch(f);
73
73
  if (e.ok) {
74
- const o = await e.json(), a = d ? d(o) : o;
75
- c(a);
74
+ const r = await e.json(), n = c ? c(r) : r;
75
+ w(n);
76
76
  } else
77
- p.error(`Error al cargar ${t} desde archivo local.`), h(`Error al obtener ${t} desde el archivo local.`);
77
+ p.error(`Error al cargar ${s} desde archivo local.`), E(`Error al obtener ${s} desde el archivo local.`);
78
78
  }
79
79
  } catch (e) {
80
- p.error(`Hubo un problema al obtener ${t}.`), console.error(`Error al obtener ${t}:`, e), h(`Error al obtener ${t}`);
80
+ p.error(`Hubo un problema al obtener ${s}.`), console.error(`Error al obtener ${s}:`, e), E(`Error al obtener ${s}`);
81
81
  }
82
- }, m = async (e, o) => {
83
- const a = new AbortController(), r = setTimeout(() => a.abort(), o);
82
+ }, A = async (e, r) => {
83
+ const n = new AbortController(), o = setTimeout(() => n.abort(), r);
84
84
  try {
85
- return await fetch(e, { signal: a.signal });
86
- } catch (s) {
87
- throw s instanceof Error ? s.name === "AbortError" ? new Error("La solicitud a la API ha tardado demasiado y fue cancelada.") : s : new Error("Un error desconocido ocurrió.");
85
+ return await fetch(e, { signal: n.signal });
86
+ } catch (t) {
87
+ throw t instanceof Error ? t.name === "AbortError" ? new Error("La solicitud a la API ha tardado demasiado y fue cancelada.") : t : new Error("Un error desconocido ocurrió.");
88
88
  } finally {
89
- clearTimeout(r);
89
+ clearTimeout(o);
90
90
  }
91
91
  };
92
- H();
93
- }, [n, w, i, l, u, v, j]), { data: I, loading: k, error: y };
92
+ C();
93
+ }, [l, $, f, u, h, v, j]), { data: k, loading: y, error: H };
94
94
  };
95
95
  export {
96
- W as useFetchData
96
+ z as useFetchData
97
97
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "react-ecosistema-unp",
3
3
  "author": "Ecosistema de Información - Unidad Nacional de Protección",
4
4
  "private": false,
5
- "version": "1.5.2-pre.1",
5
+ "version": "1.5.2-pre.2",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {