@xylex-group/athena 1.7.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/dist/react.d.cts CHANGED
@@ -1,6 +1,7 @@
1
- import { n as AthenaGatewayHookConfig, o as AthenaGatewayHookResult } from './types-wPA1Z4vQ.cjs';
2
- export { p as AthenaDeletePayload, q as AthenaFetchPayload, e as AthenaGatewayCallOptions, h as AthenaGatewayErrorCode, f as AthenaGatewayErrorDetails, r as AthenaGatewayResponse, s as AthenaInsertPayload, g as AthenaRpcCallOptions, i as AthenaRpcFilter, j as AthenaRpcFilterOperator, k as AthenaRpcOrder, l as AthenaRpcPayload, t as AthenaUpdatePayload } from './types-wPA1Z4vQ.cjs';
3
- export { A as AthenaGatewayError, i as isAthenaGatewayError } from './errors-BJGgjHcI.cjs';
1
+ import { L as AthenaGatewayHookConfig, N as AthenaGatewayHookResult } from './types-BnzoaNRC.cjs';
2
+ export { O as AthenaDeletePayload, P as AthenaFetchPayload, f as AthenaGatewayCallOptions, r as AthenaGatewayErrorCode, g as AthenaGatewayErrorDetails, Q as AthenaGatewayResponse, V as AthenaInsertPayload, s as AthenaJsonArray, h as AthenaJsonObject, t as AthenaJsonPrimitive, A as AthenaJsonValue, i as AthenaRpcCallOptions, u as AthenaRpcFilter, v as AthenaRpcFilterOperator, w as AthenaRpcOrder, x as AthenaRpcPayload, W as AthenaUpdatePayload } from './types-BnzoaNRC.cjs';
3
+ import { a7 as AthenaAuthFetchCompatibleInput, d as AthenaAuthCallOptions, y as AthenaAuthSessionResponse, i as AthenaAuthErrorDetails, v as AthenaAuthResult } from './model-form-hXkvHS_3.cjs';
4
+ export { O as AthenaGatewayError, Z as ModelFormAdapter, _ as ModelFormDefaults, $ as ModelFormNullishMode, a0 as ModelFormValues, a1 as ToModelFormDefaultsOptions, a2 as ToModelPayloadOptions, a3 as createModelFormAdapter, a4 as isAthenaGatewayError, a5 as toModelFormDefaults, a6 as toModelPayload } from './model-form-hXkvHS_3.cjs';
4
5
  import * as react from 'react';
5
6
  import { ReactNode } from 'react';
6
7
 
@@ -235,4 +236,37 @@ declare function useQuery<TQueryFnData, TData = TQueryFnData>(options: UseQueryO
235
236
 
236
237
  declare function useMutation<TVariables, TMutationFnData, TData = TMutationFnData>(options: UseMutationOptions<TVariables, TMutationFnData, TData>): UseMutationResult<TVariables, TData>;
237
238
 
238
- export { type AthenaCacheMode, type AthenaCachePolicy, AthenaGatewayHookConfig, AthenaGatewayHookResult, type AthenaMutationDefaults, type AthenaMutationEvent, type AthenaMutationRequestLog, type AthenaMutationResultData, type AthenaMutationState, AthenaQueryClient, type AthenaQueryClientConfig, AthenaQueryClientProvider, type AthenaQueryDefaults, type AthenaQueryError, type AthenaQueryEvent, type AthenaQueryRequestLog, type AthenaQueryResult, type AthenaQueryState, type AthenaResponseLike, type AthenaRetryCount, type AthenaRetryDelay, type AthenaRuntimeBaseEvent, type AthenaRuntimeEvent, type AthenaRuntimeEventType, type AthenaStateAdapter, type AthenaUnsubscribe, type QueryKey, type QueryStatus, type UseMutationOptions, type UseMutationResult, type UseQueryOptions, type UseQueryResult, attachStateAdapter, createAthenaQueryClient, useAthenaGateway, useAthenaQueryClient, useMutation, useQuery };
239
+ interface UseSessionOptions {
240
+ enabled?: boolean;
241
+ refetchOnMount?: boolean;
242
+ fetchInput?: AthenaAuthFetchCompatibleInput;
243
+ callOptions?: AthenaAuthCallOptions;
244
+ }
245
+ interface UseSessionResult<TSessionData extends AthenaAuthSessionResponse = AthenaAuthSessionResponse> {
246
+ data: TSessionData | null;
247
+ error: AthenaAuthErrorDetails | null;
248
+ isPending: boolean;
249
+ isRefetching: boolean;
250
+ refetch: () => Promise<TSessionData | null>;
251
+ }
252
+ type SessionGetter<TSessionData extends AthenaAuthSessionResponse> = (input?: AthenaAuthFetchCompatibleInput, options?: AthenaAuthCallOptions) => Promise<AthenaAuthResult<TSessionData>>;
253
+ type UseSessionAuthClient<TSessionData extends AthenaAuthSessionResponse = AthenaAuthSessionResponse> = {
254
+ getSession: SessionGetter<TSessionData>;
255
+ } | {
256
+ auth: {
257
+ getSession: SessionGetter<TSessionData>;
258
+ };
259
+ };
260
+ type InferSessionData<TClient> = TClient extends {
261
+ getSession: (...args: unknown[]) => Promise<AthenaAuthResult<infer TSessionData>>;
262
+ } ? TSessionData extends AthenaAuthSessionResponse ? TSessionData : AthenaAuthSessionResponse : TClient extends {
263
+ auth: {
264
+ getSession: (...args: unknown[]) => Promise<AthenaAuthResult<infer TSessionData>>;
265
+ };
266
+ } ? TSessionData extends AthenaAuthSessionResponse ? TSessionData : AthenaAuthSessionResponse : AthenaAuthSessionResponse;
267
+ /**
268
+ * Better Auth style session hook parity for Athena auth clients.
269
+ */
270
+ declare function useSession<TClient extends UseSessionAuthClient>(authClient: TClient, options?: UseSessionOptions): UseSessionResult<InferSessionData<TClient>>;
271
+
272
+ export { type AthenaCacheMode, type AthenaCachePolicy, AthenaGatewayHookConfig, AthenaGatewayHookResult, type AthenaMutationDefaults, type AthenaMutationEvent, type AthenaMutationRequestLog, type AthenaMutationResultData, type AthenaMutationState, AthenaQueryClient, type AthenaQueryClientConfig, AthenaQueryClientProvider, type AthenaQueryDefaults, type AthenaQueryError, type AthenaQueryEvent, type AthenaQueryRequestLog, type AthenaQueryResult, type AthenaQueryState, type AthenaResponseLike, type AthenaRetryCount, type AthenaRetryDelay, type AthenaRuntimeBaseEvent, type AthenaRuntimeEvent, type AthenaRuntimeEventType, type AthenaStateAdapter, type AthenaUnsubscribe, type QueryKey, type QueryStatus, type UseMutationOptions, type UseMutationResult, type UseQueryOptions, type UseQueryResult, type UseSessionOptions, type UseSessionResult, attachStateAdapter, createAthenaQueryClient, useAthenaGateway, useAthenaQueryClient, useMutation, useQuery, useSession };
package/dist/react.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { n as AthenaGatewayHookConfig, o as AthenaGatewayHookResult } from './types-wPA1Z4vQ.js';
2
- export { p as AthenaDeletePayload, q as AthenaFetchPayload, e as AthenaGatewayCallOptions, h as AthenaGatewayErrorCode, f as AthenaGatewayErrorDetails, r as AthenaGatewayResponse, s as AthenaInsertPayload, g as AthenaRpcCallOptions, i as AthenaRpcFilter, j as AthenaRpcFilterOperator, k as AthenaRpcOrder, l as AthenaRpcPayload, t as AthenaUpdatePayload } from './types-wPA1Z4vQ.js';
3
- export { A as AthenaGatewayError, i as isAthenaGatewayError } from './errors-Bcf5Sftv.js';
1
+ import { L as AthenaGatewayHookConfig, N as AthenaGatewayHookResult } from './types-BnzoaNRC.js';
2
+ export { O as AthenaDeletePayload, P as AthenaFetchPayload, f as AthenaGatewayCallOptions, r as AthenaGatewayErrorCode, g as AthenaGatewayErrorDetails, Q as AthenaGatewayResponse, V as AthenaInsertPayload, s as AthenaJsonArray, h as AthenaJsonObject, t as AthenaJsonPrimitive, A as AthenaJsonValue, i as AthenaRpcCallOptions, u as AthenaRpcFilter, v as AthenaRpcFilterOperator, w as AthenaRpcOrder, x as AthenaRpcPayload, W as AthenaUpdatePayload } from './types-BnzoaNRC.js';
3
+ import { a7 as AthenaAuthFetchCompatibleInput, d as AthenaAuthCallOptions, y as AthenaAuthSessionResponse, i as AthenaAuthErrorDetails, v as AthenaAuthResult } from './model-form-CVOtC8jq.js';
4
+ export { O as AthenaGatewayError, Z as ModelFormAdapter, _ as ModelFormDefaults, $ as ModelFormNullishMode, a0 as ModelFormValues, a1 as ToModelFormDefaultsOptions, a2 as ToModelPayloadOptions, a3 as createModelFormAdapter, a4 as isAthenaGatewayError, a5 as toModelFormDefaults, a6 as toModelPayload } from './model-form-CVOtC8jq.js';
4
5
  import * as react from 'react';
5
6
  import { ReactNode } from 'react';
6
7
 
@@ -235,4 +236,37 @@ declare function useQuery<TQueryFnData, TData = TQueryFnData>(options: UseQueryO
235
236
 
236
237
  declare function useMutation<TVariables, TMutationFnData, TData = TMutationFnData>(options: UseMutationOptions<TVariables, TMutationFnData, TData>): UseMutationResult<TVariables, TData>;
237
238
 
238
- export { type AthenaCacheMode, type AthenaCachePolicy, AthenaGatewayHookConfig, AthenaGatewayHookResult, type AthenaMutationDefaults, type AthenaMutationEvent, type AthenaMutationRequestLog, type AthenaMutationResultData, type AthenaMutationState, AthenaQueryClient, type AthenaQueryClientConfig, AthenaQueryClientProvider, type AthenaQueryDefaults, type AthenaQueryError, type AthenaQueryEvent, type AthenaQueryRequestLog, type AthenaQueryResult, type AthenaQueryState, type AthenaResponseLike, type AthenaRetryCount, type AthenaRetryDelay, type AthenaRuntimeBaseEvent, type AthenaRuntimeEvent, type AthenaRuntimeEventType, type AthenaStateAdapter, type AthenaUnsubscribe, type QueryKey, type QueryStatus, type UseMutationOptions, type UseMutationResult, type UseQueryOptions, type UseQueryResult, attachStateAdapter, createAthenaQueryClient, useAthenaGateway, useAthenaQueryClient, useMutation, useQuery };
239
+ interface UseSessionOptions {
240
+ enabled?: boolean;
241
+ refetchOnMount?: boolean;
242
+ fetchInput?: AthenaAuthFetchCompatibleInput;
243
+ callOptions?: AthenaAuthCallOptions;
244
+ }
245
+ interface UseSessionResult<TSessionData extends AthenaAuthSessionResponse = AthenaAuthSessionResponse> {
246
+ data: TSessionData | null;
247
+ error: AthenaAuthErrorDetails | null;
248
+ isPending: boolean;
249
+ isRefetching: boolean;
250
+ refetch: () => Promise<TSessionData | null>;
251
+ }
252
+ type SessionGetter<TSessionData extends AthenaAuthSessionResponse> = (input?: AthenaAuthFetchCompatibleInput, options?: AthenaAuthCallOptions) => Promise<AthenaAuthResult<TSessionData>>;
253
+ type UseSessionAuthClient<TSessionData extends AthenaAuthSessionResponse = AthenaAuthSessionResponse> = {
254
+ getSession: SessionGetter<TSessionData>;
255
+ } | {
256
+ auth: {
257
+ getSession: SessionGetter<TSessionData>;
258
+ };
259
+ };
260
+ type InferSessionData<TClient> = TClient extends {
261
+ getSession: (...args: unknown[]) => Promise<AthenaAuthResult<infer TSessionData>>;
262
+ } ? TSessionData extends AthenaAuthSessionResponse ? TSessionData : AthenaAuthSessionResponse : TClient extends {
263
+ auth: {
264
+ getSession: (...args: unknown[]) => Promise<AthenaAuthResult<infer TSessionData>>;
265
+ };
266
+ } ? TSessionData extends AthenaAuthSessionResponse ? TSessionData : AthenaAuthSessionResponse : AthenaAuthSessionResponse;
267
+ /**
268
+ * Better Auth style session hook parity for Athena auth clients.
269
+ */
270
+ declare function useSession<TClient extends UseSessionAuthClient>(authClient: TClient, options?: UseSessionOptions): UseSessionResult<InferSessionData<TClient>>;
271
+
272
+ export { type AthenaCacheMode, type AthenaCachePolicy, AthenaGatewayHookConfig, AthenaGatewayHookResult, type AthenaMutationDefaults, type AthenaMutationEvent, type AthenaMutationRequestLog, type AthenaMutationResultData, type AthenaMutationState, AthenaQueryClient, type AthenaQueryClientConfig, AthenaQueryClientProvider, type AthenaQueryDefaults, type AthenaQueryError, type AthenaQueryEvent, type AthenaQueryRequestLog, type AthenaQueryResult, type AthenaQueryState, type AthenaResponseLike, type AthenaRetryCount, type AthenaRetryDelay, type AthenaRuntimeBaseEvent, type AthenaRuntimeEvent, type AthenaRuntimeEventType, type AthenaStateAdapter, type AthenaUnsubscribe, type QueryKey, type QueryStatus, type UseMutationOptions, type UseMutationResult, type UseQueryOptions, type UseQueryResult, type UseSessionOptions, type UseSessionResult, attachStateAdapter, createAthenaQueryClient, useAthenaGateway, useAthenaQueryClient, useMutation, useQuery, useSession };
package/dist/react.js CHANGED
@@ -1491,7 +1491,160 @@ function useMutation(options) {
1491
1491
  lastRequest: snapshot.lastRequest
1492
1492
  };
1493
1493
  }
1494
+ function resolveGetSession(authClient) {
1495
+ if ("getSession" in authClient && typeof authClient.getSession === "function") {
1496
+ return authClient.getSession;
1497
+ }
1498
+ if ("auth" in authClient && authClient.auth && typeof authClient.auth.getSession === "function") {
1499
+ return authClient.auth.getSession;
1500
+ }
1501
+ throw new Error("useSession requires an auth-capable client (createClient(...).auth or createAuthClient(...))");
1502
+ }
1503
+ function useSession(authClient, options = {}) {
1504
+ const enabled = options.enabled ?? true;
1505
+ const refetchOnMount = options.refetchOnMount ?? true;
1506
+ const [data, setData] = useState(null);
1507
+ const [error, setError] = useState(null);
1508
+ const [isPending, setIsPending] = useState(enabled);
1509
+ const [isRefetching, setIsRefetching] = useState(false);
1510
+ const requestIdRef = useRef(0);
1511
+ const mountedRef = useRef(true);
1512
+ const dataRef = useRef(null);
1513
+ const getSession = resolveGetSession(
1514
+ authClient
1515
+ );
1516
+ useEffect(() => {
1517
+ dataRef.current = data;
1518
+ }, [data]);
1519
+ const toFallbackErrorDetails = (code, message, status) => ({
1520
+ code,
1521
+ message,
1522
+ status
1523
+ });
1524
+ const runFetch = useCallback(async () => {
1525
+ const requestId = ++requestIdRef.current;
1526
+ const hasData = dataRef.current !== null;
1527
+ if (hasData) {
1528
+ setIsRefetching(true);
1529
+ } else {
1530
+ setIsPending(true);
1531
+ }
1532
+ try {
1533
+ const result = await getSession(options.fetchInput, options.callOptions);
1534
+ if (!mountedRef.current || requestId !== requestIdRef.current) {
1535
+ return null;
1536
+ }
1537
+ if (result.ok) {
1538
+ setData(result.data ?? null);
1539
+ setError(null);
1540
+ return result.data ?? null;
1541
+ }
1542
+ setError(
1543
+ result.errorDetails ?? toFallbackErrorDetails(
1544
+ "UNKNOWN_ERROR",
1545
+ result.error ?? "Failed to fetch session",
1546
+ result.status
1547
+ )
1548
+ );
1549
+ return null;
1550
+ } catch (requestError) {
1551
+ if (!mountedRef.current || requestId !== requestIdRef.current) {
1552
+ return null;
1553
+ }
1554
+ const message = requestError instanceof Error ? requestError.message : "Failed to fetch session";
1555
+ setError(toFallbackErrorDetails("NETWORK_ERROR", message, 0));
1556
+ return null;
1557
+ } finally {
1558
+ if (mountedRef.current && requestId === requestIdRef.current) {
1559
+ setIsPending(false);
1560
+ setIsRefetching(false);
1561
+ }
1562
+ }
1563
+ }, [getSession, options.callOptions, options.fetchInput]);
1564
+ useEffect(() => {
1565
+ mountedRef.current = true;
1566
+ if (enabled && refetchOnMount) {
1567
+ void runFetch();
1568
+ } else {
1569
+ setIsPending(false);
1570
+ }
1571
+ return () => {
1572
+ mountedRef.current = false;
1573
+ };
1574
+ }, [enabled, refetchOnMount, runFetch]);
1575
+ const refetch = useCallback(async () => {
1576
+ return await runFetch();
1577
+ }, [runFetch]);
1578
+ return {
1579
+ data,
1580
+ error,
1581
+ isPending,
1582
+ isRefetching,
1583
+ refetch
1584
+ };
1585
+ }
1586
+
1587
+ // src/schema/model-form.ts
1588
+ function resolveNullishValue(mode) {
1589
+ if (mode === "undefined") return void 0;
1590
+ if (mode === "null") return null;
1591
+ return "";
1592
+ }
1593
+ function isRecord3(value) {
1594
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
1595
+ }
1596
+ function isNullableColumn(model, key) {
1597
+ const nullable = model.meta.nullable;
1598
+ return nullable?.[key] === true;
1599
+ }
1600
+ function toModelFormDefaults(model, values, options) {
1601
+ const source = values;
1602
+ if (!isRecord3(source)) {
1603
+ return {};
1604
+ }
1605
+ const mode = options?.nullishMode ?? "empty-string";
1606
+ const nullishValue = resolveNullishValue(mode);
1607
+ const result = {};
1608
+ for (const [key, value] of Object.entries(source)) {
1609
+ if (value === null && isNullableColumn(model, key)) {
1610
+ result[key] = nullishValue;
1611
+ continue;
1612
+ }
1613
+ result[key] = value;
1614
+ }
1615
+ return result;
1616
+ }
1617
+ function toModelPayload(model, formValues, options) {
1618
+ const emptyStringAsNull = options?.emptyStringAsNull ?? true;
1619
+ const stripUndefined = options?.stripUndefined ?? true;
1620
+ const result = {};
1621
+ for (const [key, rawValue] of Object.entries(formValues)) {
1622
+ if (rawValue === void 0 && stripUndefined) {
1623
+ continue;
1624
+ }
1625
+ if (emptyStringAsNull && rawValue === "" && isNullableColumn(model, key)) {
1626
+ result[key] = null;
1627
+ continue;
1628
+ }
1629
+ result[key] = rawValue;
1630
+ }
1631
+ return result;
1632
+ }
1633
+ function createModelFormAdapter(model) {
1634
+ return {
1635
+ model,
1636
+ toDefaults(values, options) {
1637
+ return toModelFormDefaults(model, values, options);
1638
+ },
1639
+ toInsert(values, options) {
1640
+ return toModelPayload(model, values, options);
1641
+ },
1642
+ toUpdate(values, options) {
1643
+ return toModelPayload(model, values, options);
1644
+ }
1645
+ };
1646
+ }
1494
1647
 
1495
- export { AthenaGatewayError, AthenaQueryClient, AthenaQueryClientProvider, attachStateAdapter, createAthenaQueryClient, isAthenaGatewayError, useAthenaGateway, useAthenaQueryClient, useMutation, useQuery };
1648
+ export { AthenaGatewayError, AthenaQueryClient, AthenaQueryClientProvider, attachStateAdapter, createAthenaQueryClient, createModelFormAdapter, isAthenaGatewayError, toModelFormDefaults, toModelPayload, useAthenaGateway, useAthenaQueryClient, useMutation, useQuery, useSession };
1496
1649
  //# sourceMappingURL=react.js.map
1497
1650
  //# sourceMappingURL=react.js.map