@xylex-group/athena 1.9.0 → 2.0.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 +40 -43
- package/bin/athena-js.js +0 -0
- package/dist/cli/index.cjs +1151 -67
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +1151 -67
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +1592 -1000
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -254
- package/dist/index.d.ts +21 -254
- package/dist/index.js +1592 -1001
- package/dist/index.js.map +1 -1
- package/dist/model-form-CVOtC8jq.d.ts +1284 -0
- package/dist/model-form-hXkvHS_3.d.cts +1284 -0
- package/dist/react.cjs +93 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +36 -2
- package/dist/react.d.ts +36 -2
- package/dist/react.js +93 -1
- package/dist/react.js.map +1 -1
- package/package.json +16 -17
- package/dist/model-form-Bm_kqCn2.d.ts +0 -92
- package/dist/model-form-DkS48fsh.d.cts +0 -92
package/dist/react.cjs
CHANGED
|
@@ -1493,6 +1493,98 @@ function useMutation(options) {
|
|
|
1493
1493
|
lastRequest: snapshot.lastRequest
|
|
1494
1494
|
};
|
|
1495
1495
|
}
|
|
1496
|
+
function resolveGetSession(authClient) {
|
|
1497
|
+
if ("getSession" in authClient && typeof authClient.getSession === "function") {
|
|
1498
|
+
return authClient.getSession;
|
|
1499
|
+
}
|
|
1500
|
+
if ("auth" in authClient && authClient.auth && typeof authClient.auth.getSession === "function") {
|
|
1501
|
+
return authClient.auth.getSession;
|
|
1502
|
+
}
|
|
1503
|
+
throw new Error("useSession requires an auth-capable client (createClient(...).auth or createAuthClient(...))");
|
|
1504
|
+
}
|
|
1505
|
+
function useSession(authClient, options = {}) {
|
|
1506
|
+
const enabled = options.enabled ?? true;
|
|
1507
|
+
const refetchOnMount = options.refetchOnMount ?? true;
|
|
1508
|
+
const [data, setData] = react.useState(null);
|
|
1509
|
+
const [error, setError] = react.useState(null);
|
|
1510
|
+
const [isPending, setIsPending] = react.useState(enabled);
|
|
1511
|
+
const [isRefetching, setIsRefetching] = react.useState(false);
|
|
1512
|
+
const requestIdRef = react.useRef(0);
|
|
1513
|
+
const mountedRef = react.useRef(true);
|
|
1514
|
+
const dataRef = react.useRef(null);
|
|
1515
|
+
const getSession = resolveGetSession(
|
|
1516
|
+
authClient
|
|
1517
|
+
);
|
|
1518
|
+
react.useEffect(() => {
|
|
1519
|
+
dataRef.current = data;
|
|
1520
|
+
}, [data]);
|
|
1521
|
+
const toFallbackErrorDetails = (code, message, status) => ({
|
|
1522
|
+
code,
|
|
1523
|
+
message,
|
|
1524
|
+
status
|
|
1525
|
+
});
|
|
1526
|
+
const runFetch = react.useCallback(async () => {
|
|
1527
|
+
const requestId = ++requestIdRef.current;
|
|
1528
|
+
const hasData = dataRef.current !== null;
|
|
1529
|
+
if (hasData) {
|
|
1530
|
+
setIsRefetching(true);
|
|
1531
|
+
} else {
|
|
1532
|
+
setIsPending(true);
|
|
1533
|
+
}
|
|
1534
|
+
try {
|
|
1535
|
+
const result = await getSession(options.fetchInput, options.callOptions);
|
|
1536
|
+
if (!mountedRef.current || requestId !== requestIdRef.current) {
|
|
1537
|
+
return null;
|
|
1538
|
+
}
|
|
1539
|
+
if (result.ok) {
|
|
1540
|
+
setData(result.data ?? null);
|
|
1541
|
+
setError(null);
|
|
1542
|
+
return result.data ?? null;
|
|
1543
|
+
}
|
|
1544
|
+
setError(
|
|
1545
|
+
result.errorDetails ?? toFallbackErrorDetails(
|
|
1546
|
+
"UNKNOWN_ERROR",
|
|
1547
|
+
result.error ?? "Failed to fetch session",
|
|
1548
|
+
result.status
|
|
1549
|
+
)
|
|
1550
|
+
);
|
|
1551
|
+
return null;
|
|
1552
|
+
} catch (requestError) {
|
|
1553
|
+
if (!mountedRef.current || requestId !== requestIdRef.current) {
|
|
1554
|
+
return null;
|
|
1555
|
+
}
|
|
1556
|
+
const message = requestError instanceof Error ? requestError.message : "Failed to fetch session";
|
|
1557
|
+
setError(toFallbackErrorDetails("NETWORK_ERROR", message, 0));
|
|
1558
|
+
return null;
|
|
1559
|
+
} finally {
|
|
1560
|
+
if (mountedRef.current && requestId === requestIdRef.current) {
|
|
1561
|
+
setIsPending(false);
|
|
1562
|
+
setIsRefetching(false);
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
}, [getSession, options.callOptions, options.fetchInput]);
|
|
1566
|
+
react.useEffect(() => {
|
|
1567
|
+
mountedRef.current = true;
|
|
1568
|
+
if (enabled && refetchOnMount) {
|
|
1569
|
+
void runFetch();
|
|
1570
|
+
} else {
|
|
1571
|
+
setIsPending(false);
|
|
1572
|
+
}
|
|
1573
|
+
return () => {
|
|
1574
|
+
mountedRef.current = false;
|
|
1575
|
+
};
|
|
1576
|
+
}, [enabled, refetchOnMount, runFetch]);
|
|
1577
|
+
const refetch = react.useCallback(async () => {
|
|
1578
|
+
return await runFetch();
|
|
1579
|
+
}, [runFetch]);
|
|
1580
|
+
return {
|
|
1581
|
+
data,
|
|
1582
|
+
error,
|
|
1583
|
+
isPending,
|
|
1584
|
+
isRefetching,
|
|
1585
|
+
refetch
|
|
1586
|
+
};
|
|
1587
|
+
}
|
|
1496
1588
|
|
|
1497
1589
|
// src/schema/model-form.ts
|
|
1498
1590
|
function resolveNullishValue(mode) {
|
|
@@ -1568,5 +1660,6 @@ exports.useAthenaGateway = useAthenaGateway;
|
|
|
1568
1660
|
exports.useAthenaQueryClient = useAthenaQueryClient;
|
|
1569
1661
|
exports.useMutation = useMutation;
|
|
1570
1662
|
exports.useQuery = useQuery;
|
|
1663
|
+
exports.useSession = useSession;
|
|
1571
1664
|
//# sourceMappingURL=react.cjs.map
|
|
1572
1665
|
//# sourceMappingURL=react.cjs.map
|