@xylex-group/athena 2.6.0 → 2.7.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/README.md +1 -1
- package/dist/browser.cjs +837 -114
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +7 -7
- package/dist/browser.d.ts +7 -7
- package/dist/browser.js +837 -114
- package/dist/browser.js.map +1 -1
- package/dist/cli/index.cjs +830 -107
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +3 -3
- package/dist/cli/index.d.ts +3 -3
- package/dist/cli/index.js +830 -107
- package/dist/cli/index.js.map +1 -1
- package/dist/cookies.cjs +10 -3
- package/dist/cookies.cjs.map +1 -1
- package/dist/cookies.js +10 -3
- package/dist/cookies.js.map +1 -1
- package/dist/index.cjs +837 -114
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +837 -114
- package/dist/index.js.map +1 -1
- package/dist/model-form-AKYrgede.d.ts +2772 -0
- package/dist/model-form-ehfqLuG7.d.cts +2772 -0
- package/dist/{pipeline-Ce3pTw5h.d.ts → pipeline-BUsR9XlO.d.ts} +1 -1
- package/dist/{pipeline-D1ZYeoH7.d.cts → pipeline-BfCWSRYl.d.cts} +1 -1
- package/dist/react-email-BQzmXBDE.d.cts +304 -0
- package/dist/react-email-BrVRp80B.d.ts +304 -0
- package/dist/react.cjs +178 -71
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +22 -5
- package/dist/react.d.ts +22 -5
- package/dist/react.js +92 -5
- package/dist/react.js.map +1 -1
- package/dist/{types-CUuo4NDi.d.cts → types-BSIsyss1.d.cts} +1 -1
- package/dist/{types-DSX6AT5B.d.cts → types-BsyRW49r.d.cts} +1 -1
- package/dist/{types-DSX6AT5B.d.ts → types-BsyRW49r.d.ts} +1 -1
- package/dist/{types-DapchQY5.d.ts → types-t_TVqnmp.d.ts} +1 -1
- package/package.json +193 -193
- package/dist/model-form-BaHWi3gm.d.cts +0 -1383
- package/dist/model-form-Dh6gWjL0.d.ts +0 -1383
- package/dist/react-email-B8O1Jeff.d.cts +0 -1230
- package/dist/react-email-CDEF0jij.d.ts +0 -1230
package/dist/react.cjs
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var React = require('react');
|
|
4
4
|
var shim = require('use-sync-external-store/shim');
|
|
5
5
|
|
|
6
|
+
function _interopNamespace(e) {
|
|
7
|
+
if (e && e.__esModule) return e;
|
|
8
|
+
var n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
Object.keys(e).forEach(function (k) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return e[k]; }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
25
|
+
|
|
6
26
|
// src/gateway/use-athena-gateway.ts
|
|
7
27
|
|
|
8
28
|
// src/gateway/errors.ts
|
|
@@ -151,16 +171,23 @@ var getSessionCookie = (request, config) => {
|
|
|
151
171
|
const { cookieName = "session_token", cookiePrefix = "athena-auth" } = {};
|
|
152
172
|
const parsedCookie = parseCookies(cookies);
|
|
153
173
|
const getCookie = (name) => parsedCookie.get(name) || parsedCookie.get(`${SECURE_COOKIE_PREFIX}${name}`);
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
174
|
+
const candidateCookieNames = Array.from(/* @__PURE__ */ new Set([
|
|
175
|
+
cookieName,
|
|
176
|
+
cookieName.replace(/_/g, "-"),
|
|
177
|
+
cookieName.replace(/-/g, "_")
|
|
178
|
+
])).filter(Boolean);
|
|
179
|
+
for (const candidateName of candidateCookieNames) {
|
|
180
|
+
const sessionToken = getCookie(`${cookiePrefix}.${candidateName}`) || getCookie(`${cookiePrefix}-${candidateName}`);
|
|
181
|
+
if (sessionToken) {
|
|
182
|
+
return sessionToken;
|
|
183
|
+
}
|
|
157
184
|
}
|
|
158
185
|
return null;
|
|
159
186
|
};
|
|
160
187
|
|
|
161
188
|
// package.json
|
|
162
189
|
var package_default = {
|
|
163
|
-
version: "2.
|
|
190
|
+
version: "2.7.0"
|
|
164
191
|
};
|
|
165
192
|
|
|
166
193
|
// src/sdk-version.ts
|
|
@@ -711,13 +738,13 @@ function createAthenaGatewayClient(config = {}) {
|
|
|
711
738
|
|
|
712
739
|
// src/gateway/use-athena-gateway.ts
|
|
713
740
|
function useAthenaGateway(config) {
|
|
714
|
-
const [isLoading, setIsLoading] =
|
|
715
|
-
const [error, setError] =
|
|
716
|
-
const [lastRequest, setLastRequest] =
|
|
741
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
742
|
+
const [error, setError] = React.useState(null);
|
|
743
|
+
const [lastRequest, setLastRequest] = React.useState(
|
|
717
744
|
null
|
|
718
745
|
);
|
|
719
|
-
const [lastResponse, setLastResponse] =
|
|
720
|
-
const client =
|
|
746
|
+
const [lastResponse, setLastResponse] = React.useState(null);
|
|
747
|
+
const client = React.useMemo(
|
|
721
748
|
() => createAthenaGatewayClient({
|
|
722
749
|
client: config?.client,
|
|
723
750
|
baseUrl: config?.baseUrl,
|
|
@@ -739,7 +766,7 @@ function useAthenaGateway(config) {
|
|
|
739
766
|
config?.organizationId
|
|
740
767
|
]
|
|
741
768
|
);
|
|
742
|
-
const callWithLifecycle =
|
|
769
|
+
const callWithLifecycle = React.useCallback(
|
|
743
770
|
async (fn, metadata) => {
|
|
744
771
|
const requestLog = {
|
|
745
772
|
endpoint: metadata.endpoint,
|
|
@@ -791,7 +818,7 @@ function useAthenaGateway(config) {
|
|
|
791
818
|
[client]
|
|
792
819
|
);
|
|
793
820
|
const defaultStripNulls = true;
|
|
794
|
-
const fetchGateway =
|
|
821
|
+
const fetchGateway = React.useCallback(
|
|
795
822
|
(payload, options) => {
|
|
796
823
|
const normalizedPayload = {
|
|
797
824
|
...payload,
|
|
@@ -810,7 +837,7 @@ function useAthenaGateway(config) {
|
|
|
810
837
|
},
|
|
811
838
|
[callWithLifecycle, client]
|
|
812
839
|
);
|
|
813
|
-
const insertGateway =
|
|
840
|
+
const insertGateway = React.useCallback(
|
|
814
841
|
(payload, options) => callWithLifecycle(() => client.insertGateway(payload, options), {
|
|
815
842
|
endpoint: "/gateway/insert",
|
|
816
843
|
method: "PUT",
|
|
@@ -819,7 +846,7 @@ function useAthenaGateway(config) {
|
|
|
819
846
|
}),
|
|
820
847
|
[callWithLifecycle, client]
|
|
821
848
|
);
|
|
822
|
-
const updateGateway =
|
|
849
|
+
const updateGateway = React.useCallback(
|
|
823
850
|
(payload, options) => {
|
|
824
851
|
const normalizedPayload = {
|
|
825
852
|
...payload,
|
|
@@ -838,7 +865,7 @@ function useAthenaGateway(config) {
|
|
|
838
865
|
},
|
|
839
866
|
[callWithLifecycle, client]
|
|
840
867
|
);
|
|
841
|
-
const deleteGateway =
|
|
868
|
+
const deleteGateway = React.useCallback(
|
|
842
869
|
(payload, options) => {
|
|
843
870
|
if (!payload.resource_id) {
|
|
844
871
|
throw new Error(
|
|
@@ -852,7 +879,7 @@ function useAthenaGateway(config) {
|
|
|
852
879
|
},
|
|
853
880
|
[callWithLifecycle, client]
|
|
854
881
|
);
|
|
855
|
-
const rpcGateway =
|
|
882
|
+
const rpcGateway = React.useCallback(
|
|
856
883
|
(payload, options) => callWithLifecycle(() => client.rpcGateway(payload, options), {
|
|
857
884
|
endpoint: options?.get ? `/rpc/${payload.function}` : "/gateway/rpc",
|
|
858
885
|
method: options?.get ? "GET" : "POST",
|
|
@@ -1566,22 +1593,22 @@ function createAthenaQueryClient(config) {
|
|
|
1566
1593
|
function attachStateAdapter(client, adapter) {
|
|
1567
1594
|
return client.attachAdapter(adapter);
|
|
1568
1595
|
}
|
|
1569
|
-
var AthenaQueryClientContext =
|
|
1596
|
+
var AthenaQueryClientContext = React.createContext(null);
|
|
1570
1597
|
function AthenaQueryClientProvider(props) {
|
|
1571
|
-
const memoizedClient =
|
|
1598
|
+
const memoizedClient = React.useMemo(() => {
|
|
1572
1599
|
if (props.client) {
|
|
1573
1600
|
return props.client;
|
|
1574
1601
|
}
|
|
1575
1602
|
return createAthenaQueryClient(props.config);
|
|
1576
1603
|
}, [props.client, props.config]);
|
|
1577
|
-
return
|
|
1604
|
+
return React.createElement(
|
|
1578
1605
|
AthenaQueryClientContext.Provider,
|
|
1579
1606
|
{ value: memoizedClient },
|
|
1580
1607
|
props.children
|
|
1581
1608
|
);
|
|
1582
1609
|
}
|
|
1583
1610
|
function useAthenaQueryClient() {
|
|
1584
|
-
const client =
|
|
1611
|
+
const client = React.useContext(AthenaQueryClientContext);
|
|
1585
1612
|
if (!client) {
|
|
1586
1613
|
throw new Error(
|
|
1587
1614
|
"No AthenaQueryClient found. Wrap your component tree with AthenaQueryClientProvider."
|
|
@@ -1602,48 +1629,48 @@ function getBrowserTarget() {
|
|
|
1602
1629
|
}
|
|
1603
1630
|
function useQuery(options) {
|
|
1604
1631
|
const client = useAthenaQueryClient();
|
|
1605
|
-
const queryKeyRef =
|
|
1632
|
+
const queryKeyRef = React.useRef(options.queryKey);
|
|
1606
1633
|
queryKeyRef.current = options.queryKey;
|
|
1607
|
-
const queryFnRef =
|
|
1634
|
+
const queryFnRef = React.useRef(options.queryFn);
|
|
1608
1635
|
queryFnRef.current = options.queryFn;
|
|
1609
|
-
const selectRef =
|
|
1636
|
+
const selectRef = React.useRef(options.select);
|
|
1610
1637
|
selectRef.current = options.select;
|
|
1611
|
-
const onSuccessRef =
|
|
1638
|
+
const onSuccessRef = React.useRef(options.onSuccess);
|
|
1612
1639
|
onSuccessRef.current = options.onSuccess;
|
|
1613
|
-
const onErrorRef =
|
|
1640
|
+
const onErrorRef = React.useRef(options.onError);
|
|
1614
1641
|
onErrorRef.current = options.onError;
|
|
1615
|
-
const onSettledRef =
|
|
1642
|
+
const onSettledRef = React.useRef(options.onSettled);
|
|
1616
1643
|
onSettledRef.current = options.onSettled;
|
|
1617
|
-
const enabledRef =
|
|
1644
|
+
const enabledRef = React.useRef(options.enabled ?? true);
|
|
1618
1645
|
enabledRef.current = options.enabled ?? true;
|
|
1619
|
-
const retryRef =
|
|
1646
|
+
const retryRef = React.useRef(options.retry);
|
|
1620
1647
|
retryRef.current = options.retry;
|
|
1621
|
-
const retryDelayRef =
|
|
1648
|
+
const retryDelayRef = React.useRef(options.retryDelay);
|
|
1622
1649
|
retryDelayRef.current = options.retryDelay;
|
|
1623
|
-
const initialDataRef =
|
|
1650
|
+
const initialDataRef = React.useRef(options.initialData);
|
|
1624
1651
|
initialDataRef.current = options.initialData;
|
|
1625
|
-
const refetchOnMountRef =
|
|
1652
|
+
const refetchOnMountRef = React.useRef(options.refetchOnMount);
|
|
1626
1653
|
refetchOnMountRef.current = options.refetchOnMount;
|
|
1627
|
-
const refetchOnWindowFocusRef =
|
|
1654
|
+
const refetchOnWindowFocusRef = React.useRef(options.refetchOnWindowFocus);
|
|
1628
1655
|
refetchOnWindowFocusRef.current = options.refetchOnWindowFocus;
|
|
1629
|
-
const refetchOnReconnectRef =
|
|
1656
|
+
const refetchOnReconnectRef = React.useRef(options.refetchOnReconnect);
|
|
1630
1657
|
refetchOnReconnectRef.current = options.refetchOnReconnect;
|
|
1631
|
-
const queryKeyToken =
|
|
1658
|
+
const queryKeyToken = React.useMemo(
|
|
1632
1659
|
() => client.getQueryKeyToken(options.queryKey),
|
|
1633
1660
|
[client, options.queryKey]
|
|
1634
1661
|
);
|
|
1635
|
-
const activeQueryKeyTokenRef =
|
|
1662
|
+
const activeQueryKeyTokenRef = React.useRef(queryKeyToken);
|
|
1636
1663
|
activeQueryKeyTokenRef.current = queryKeyToken;
|
|
1637
|
-
const subscribe =
|
|
1664
|
+
const subscribe = React.useCallback(
|
|
1638
1665
|
(listener) => client.subscribeQuery(queryKeyToken, listener),
|
|
1639
1666
|
[client, queryKeyToken]
|
|
1640
1667
|
);
|
|
1641
|
-
const getSnapshot =
|
|
1668
|
+
const getSnapshot = React.useCallback(
|
|
1642
1669
|
() => client.getQueryState(queryKeyToken),
|
|
1643
1670
|
[client, queryKeyToken]
|
|
1644
1671
|
);
|
|
1645
1672
|
const snapshot = shim.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
1646
|
-
const effectiveSnapshot =
|
|
1673
|
+
const effectiveSnapshot = React.useMemo(() => {
|
|
1647
1674
|
if (snapshot.status === "idle" && snapshot.data === void 0 && initialDataRef.current !== void 0) {
|
|
1648
1675
|
return {
|
|
1649
1676
|
...snapshot,
|
|
@@ -1654,7 +1681,7 @@ function useQuery(options) {
|
|
|
1654
1681
|
}
|
|
1655
1682
|
return snapshot;
|
|
1656
1683
|
}, [snapshot]);
|
|
1657
|
-
const runQuery =
|
|
1684
|
+
const runQuery = React.useCallback(
|
|
1658
1685
|
async (force = false) => {
|
|
1659
1686
|
const result = await client.executeQuery({
|
|
1660
1687
|
queryKey: queryKeyRef.current,
|
|
@@ -1681,8 +1708,8 @@ function useQuery(options) {
|
|
|
1681
1708
|
},
|
|
1682
1709
|
[client, queryKeyToken]
|
|
1683
1710
|
);
|
|
1684
|
-
const lastAutoKeyRef =
|
|
1685
|
-
|
|
1711
|
+
const lastAutoKeyRef = React.useRef(null);
|
|
1712
|
+
React.useEffect(() => {
|
|
1686
1713
|
const refetchOnMount = refetchOnMountRef.current ?? client.defaultQueryOptions.refetchOnMount ?? true;
|
|
1687
1714
|
const isFirstRenderForKey = lastAutoKeyRef.current !== queryKeyToken;
|
|
1688
1715
|
lastAutoKeyRef.current = queryKeyToken;
|
|
@@ -1695,7 +1722,7 @@ function useQuery(options) {
|
|
|
1695
1722
|
void runQuery(false);
|
|
1696
1723
|
}
|
|
1697
1724
|
}, [client, queryKeyToken, runQuery]);
|
|
1698
|
-
|
|
1725
|
+
React.useEffect(() => {
|
|
1699
1726
|
const browser = getBrowserTarget();
|
|
1700
1727
|
if (!browser || !enabledRef.current) {
|
|
1701
1728
|
return void 0;
|
|
@@ -1713,7 +1740,7 @@ function useQuery(options) {
|
|
|
1713
1740
|
browser.removeEventListener("focus", onFocus);
|
|
1714
1741
|
};
|
|
1715
1742
|
}, [client, runQuery]);
|
|
1716
|
-
|
|
1743
|
+
React.useEffect(() => {
|
|
1717
1744
|
const browser = getBrowserTarget();
|
|
1718
1745
|
if (!browser || !enabledRef.current) {
|
|
1719
1746
|
return void 0;
|
|
@@ -1731,8 +1758,8 @@ function useQuery(options) {
|
|
|
1731
1758
|
browser.removeEventListener("online", onReconnect);
|
|
1732
1759
|
};
|
|
1733
1760
|
}, [client, runQuery]);
|
|
1734
|
-
const refetch =
|
|
1735
|
-
const reset =
|
|
1761
|
+
const refetch = React.useCallback(() => runQuery(true), [runQuery]);
|
|
1762
|
+
const reset = React.useCallback(() => {
|
|
1736
1763
|
client.resetQuery(queryKeyRef.current);
|
|
1737
1764
|
}, [client]);
|
|
1738
1765
|
return {
|
|
@@ -1751,38 +1778,38 @@ function useQuery(options) {
|
|
|
1751
1778
|
}
|
|
1752
1779
|
function useMutation(options) {
|
|
1753
1780
|
const client = useAthenaQueryClient();
|
|
1754
|
-
const mutationKeyRef =
|
|
1781
|
+
const mutationKeyRef = React.useRef(options.mutationKey);
|
|
1755
1782
|
mutationKeyRef.current = options.mutationKey;
|
|
1756
|
-
const mutationFnRef =
|
|
1783
|
+
const mutationFnRef = React.useRef(options.mutationFn);
|
|
1757
1784
|
mutationFnRef.current = options.mutationFn;
|
|
1758
|
-
const selectRef =
|
|
1785
|
+
const selectRef = React.useRef(options.select);
|
|
1759
1786
|
selectRef.current = options.select;
|
|
1760
|
-
const retryRef =
|
|
1787
|
+
const retryRef = React.useRef(options.retry);
|
|
1761
1788
|
retryRef.current = options.retry;
|
|
1762
|
-
const retryDelayRef =
|
|
1789
|
+
const retryDelayRef = React.useRef(options.retryDelay);
|
|
1763
1790
|
retryDelayRef.current = options.retryDelay;
|
|
1764
|
-
const onMutateRef =
|
|
1791
|
+
const onMutateRef = React.useRef(options.onMutate);
|
|
1765
1792
|
onMutateRef.current = options.onMutate;
|
|
1766
|
-
const onSuccessRef =
|
|
1793
|
+
const onSuccessRef = React.useRef(options.onSuccess);
|
|
1767
1794
|
onSuccessRef.current = options.onSuccess;
|
|
1768
|
-
const onErrorRef =
|
|
1795
|
+
const onErrorRef = React.useRef(options.onError);
|
|
1769
1796
|
onErrorRef.current = options.onError;
|
|
1770
|
-
const onSettledRef =
|
|
1797
|
+
const onSettledRef = React.useRef(options.onSettled);
|
|
1771
1798
|
onSettledRef.current = options.onSettled;
|
|
1772
|
-
const mutationKeyToken =
|
|
1799
|
+
const mutationKeyToken = React.useMemo(
|
|
1773
1800
|
() => client.getMutationKeyToken(options.mutationKey),
|
|
1774
1801
|
[client, options.mutationKey]
|
|
1775
1802
|
);
|
|
1776
|
-
const subscribe =
|
|
1803
|
+
const subscribe = React.useCallback(
|
|
1777
1804
|
(listener) => client.subscribeMutation(mutationKeyToken, listener),
|
|
1778
1805
|
[client, mutationKeyToken]
|
|
1779
1806
|
);
|
|
1780
|
-
const getSnapshot =
|
|
1807
|
+
const getSnapshot = React.useCallback(
|
|
1781
1808
|
() => client.getMutationState(mutationKeyToken),
|
|
1782
1809
|
[client, mutationKeyToken]
|
|
1783
1810
|
);
|
|
1784
1811
|
const snapshot = shim.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
1785
|
-
const mutateAsync =
|
|
1812
|
+
const mutateAsync = React.useCallback(
|
|
1786
1813
|
async (variables) => {
|
|
1787
1814
|
await onMutateRef.current?.(variables);
|
|
1788
1815
|
const result = await client.executeMutation({
|
|
@@ -1806,13 +1833,13 @@ function useMutation(options) {
|
|
|
1806
1833
|
},
|
|
1807
1834
|
[client, mutationKeyToken]
|
|
1808
1835
|
);
|
|
1809
|
-
const mutate =
|
|
1836
|
+
const mutate = React.useCallback(
|
|
1810
1837
|
(variables) => {
|
|
1811
1838
|
void mutateAsync(variables).catch(() => void 0);
|
|
1812
1839
|
},
|
|
1813
1840
|
[mutateAsync]
|
|
1814
1841
|
);
|
|
1815
|
-
const reset =
|
|
1842
|
+
const reset = React.useCallback(() => {
|
|
1816
1843
|
client.resetMutation(mutationKeyRef.current);
|
|
1817
1844
|
}, [client]);
|
|
1818
1845
|
return {
|
|
@@ -1843,17 +1870,17 @@ function resolveGetSession(authClient) {
|
|
|
1843
1870
|
function useSession(authClient, options = {}) {
|
|
1844
1871
|
const enabled = options.enabled ?? true;
|
|
1845
1872
|
const refetchOnMount = options.refetchOnMount ?? true;
|
|
1846
|
-
const [data, setData] =
|
|
1847
|
-
const [error, setError] =
|
|
1848
|
-
const [isPending, setIsPending] =
|
|
1849
|
-
const [isRefetching, setIsRefetching] =
|
|
1850
|
-
const requestIdRef =
|
|
1851
|
-
const mountedRef =
|
|
1852
|
-
const dataRef =
|
|
1873
|
+
const [data, setData] = React.useState(null);
|
|
1874
|
+
const [error, setError] = React.useState(null);
|
|
1875
|
+
const [isPending, setIsPending] = React.useState(enabled);
|
|
1876
|
+
const [isRefetching, setIsRefetching] = React.useState(false);
|
|
1877
|
+
const requestIdRef = React.useRef(0);
|
|
1878
|
+
const mountedRef = React.useRef(true);
|
|
1879
|
+
const dataRef = React.useRef(null);
|
|
1853
1880
|
const getSession = resolveGetSession(
|
|
1854
1881
|
authClient
|
|
1855
1882
|
);
|
|
1856
|
-
|
|
1883
|
+
React.useEffect(() => {
|
|
1857
1884
|
dataRef.current = data;
|
|
1858
1885
|
}, [data]);
|
|
1859
1886
|
const toFallbackErrorDetails = (code, message, status) => ({
|
|
@@ -1861,7 +1888,7 @@ function useSession(authClient, options = {}) {
|
|
|
1861
1888
|
message,
|
|
1862
1889
|
status
|
|
1863
1890
|
});
|
|
1864
|
-
const runFetch =
|
|
1891
|
+
const runFetch = React.useCallback(async () => {
|
|
1865
1892
|
const requestId = ++requestIdRef.current;
|
|
1866
1893
|
const hasData = dataRef.current !== null;
|
|
1867
1894
|
if (hasData) {
|
|
@@ -1901,7 +1928,7 @@ function useSession(authClient, options = {}) {
|
|
|
1901
1928
|
}
|
|
1902
1929
|
}
|
|
1903
1930
|
}, [getSession, options.callOptions, options.fetchInput]);
|
|
1904
|
-
|
|
1931
|
+
React.useEffect(() => {
|
|
1905
1932
|
mountedRef.current = true;
|
|
1906
1933
|
if (enabled && refetchOnMount) {
|
|
1907
1934
|
void runFetch();
|
|
@@ -1912,7 +1939,7 @@ function useSession(authClient, options = {}) {
|
|
|
1912
1939
|
mountedRef.current = false;
|
|
1913
1940
|
};
|
|
1914
1941
|
}, [enabled, refetchOnMount, runFetch]);
|
|
1915
|
-
const refetch =
|
|
1942
|
+
const refetch = React.useCallback(async () => {
|
|
1916
1943
|
return await runFetch();
|
|
1917
1944
|
}, [runFetch]);
|
|
1918
1945
|
return {
|
|
@@ -1923,6 +1950,85 @@ function useSession(authClient, options = {}) {
|
|
|
1923
1950
|
refetch
|
|
1924
1951
|
};
|
|
1925
1952
|
}
|
|
1953
|
+
function useStorageUpload(options) {
|
|
1954
|
+
const {
|
|
1955
|
+
storage,
|
|
1956
|
+
onProgress,
|
|
1957
|
+
...defaults
|
|
1958
|
+
} = options;
|
|
1959
|
+
const [uploading, setUploading] = React__namespace.useState(false);
|
|
1960
|
+
const [progress, setProgress] = React__namespace.useState(null);
|
|
1961
|
+
const [error, setError] = React__namespace.useState(null);
|
|
1962
|
+
const [result, setResult] = React__namespace.useState(null);
|
|
1963
|
+
const controllerRef = React__namespace.useRef(null);
|
|
1964
|
+
const reset = React__namespace.useCallback(() => {
|
|
1965
|
+
setUploading(false);
|
|
1966
|
+
setProgress(null);
|
|
1967
|
+
setError(null);
|
|
1968
|
+
setResult(null);
|
|
1969
|
+
}, []);
|
|
1970
|
+
const abort = React__namespace.useCallback(() => {
|
|
1971
|
+
controllerRef.current?.abort();
|
|
1972
|
+
controllerRef.current = null;
|
|
1973
|
+
}, []);
|
|
1974
|
+
const upload = React__namespace.useCallback(async (input, callOptions) => {
|
|
1975
|
+
const controller = callOptions?.signal ? null : new AbortController();
|
|
1976
|
+
controllerRef.current = controller;
|
|
1977
|
+
setUploading(true);
|
|
1978
|
+
setError(null);
|
|
1979
|
+
setResult(null);
|
|
1980
|
+
const request = normalizeHookUploadInput(defaults, input, (progressEvent) => {
|
|
1981
|
+
setProgress(progressEvent);
|
|
1982
|
+
onProgress?.(progressEvent);
|
|
1983
|
+
if (isStorageUploadInput(input)) {
|
|
1984
|
+
input.onProgress?.(progressEvent);
|
|
1985
|
+
}
|
|
1986
|
+
});
|
|
1987
|
+
try {
|
|
1988
|
+
const uploaded = await storage.file.upload(request, {
|
|
1989
|
+
...callOptions,
|
|
1990
|
+
signal: callOptions?.signal ?? controller?.signal
|
|
1991
|
+
});
|
|
1992
|
+
setResult(uploaded);
|
|
1993
|
+
return uploaded;
|
|
1994
|
+
} catch (uploadError) {
|
|
1995
|
+
setError(uploadError);
|
|
1996
|
+
throw uploadError;
|
|
1997
|
+
} finally {
|
|
1998
|
+
setUploading(false);
|
|
1999
|
+
if (controllerRef.current === controller) {
|
|
2000
|
+
controllerRef.current = null;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
}, [defaults, onProgress, storage]);
|
|
2004
|
+
return {
|
|
2005
|
+
uploading,
|
|
2006
|
+
progress,
|
|
2007
|
+
percent: progress?.aggregatePercent ?? 0,
|
|
2008
|
+
error,
|
|
2009
|
+
result,
|
|
2010
|
+
upload,
|
|
2011
|
+
abort,
|
|
2012
|
+
reset
|
|
2013
|
+
};
|
|
2014
|
+
}
|
|
2015
|
+
function normalizeHookUploadInput(defaults, input, onProgress) {
|
|
2016
|
+
if (isStorageUploadInput(input)) {
|
|
2017
|
+
return {
|
|
2018
|
+
...defaults,
|
|
2019
|
+
...input,
|
|
2020
|
+
onProgress
|
|
2021
|
+
};
|
|
2022
|
+
}
|
|
2023
|
+
return {
|
|
2024
|
+
...defaults,
|
|
2025
|
+
files: input,
|
|
2026
|
+
onProgress
|
|
2027
|
+
};
|
|
2028
|
+
}
|
|
2029
|
+
function isStorageUploadInput(input) {
|
|
2030
|
+
return Boolean(input) && typeof input === "object" && "files" in input && "s3_id" in input;
|
|
2031
|
+
}
|
|
1926
2032
|
|
|
1927
2033
|
// src/schema/model-form.ts
|
|
1928
2034
|
function resolveNullishValue(mode) {
|
|
@@ -1999,5 +2105,6 @@ exports.useAthenaQueryClient = useAthenaQueryClient;
|
|
|
1999
2105
|
exports.useMutation = useMutation;
|
|
2000
2106
|
exports.useQuery = useQuery;
|
|
2001
2107
|
exports.useSession = useSession;
|
|
2108
|
+
exports.useStorageUpload = useStorageUpload;
|
|
2002
2109
|
//# sourceMappingURL=react.cjs.map
|
|
2003
2110
|
//# sourceMappingURL=react.cjs.map
|