@pol-studios/db 1.0.37 → 1.0.39

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.
Files changed (39) hide show
  1. package/dist/UserMetadataContext-yLZQu24J.d.ts +33 -0
  2. package/dist/auth/context.d.ts +5 -59
  3. package/dist/auth/context.js +2 -26
  4. package/dist/auth/hooks.d.ts +3 -107
  5. package/dist/auth/hooks.js +3 -9
  6. package/dist/auth/index.d.ts +5 -5
  7. package/dist/auth/index.js +10 -40
  8. package/dist/{chunk-7P2LGZYQ.js → chunk-3UW5K5PL.js} +3 -3
  9. package/dist/{chunk-UBHORKBS.js → chunk-5SJ5O2NQ.js} +75 -2
  10. package/dist/chunk-5SJ5O2NQ.js.map +1 -0
  11. package/dist/{chunk-X747EEWD.js → chunk-AQ5JJKIN.js} +4 -4
  12. package/dist/{chunk-NP34C3O3.js → chunk-D2F3APBF.js} +30 -103
  13. package/dist/chunk-D2F3APBF.js.map +1 -0
  14. package/dist/{chunk-7NFMEDJW.js → chunk-D7UZEYKO.js} +9 -42
  15. package/dist/chunk-D7UZEYKO.js.map +1 -0
  16. package/dist/{chunk-YQUNORJD.js → chunk-MZLEDWJF.js} +310 -392
  17. package/dist/chunk-MZLEDWJF.js.map +1 -0
  18. package/dist/chunk-NSIAAYW3.js +1 -0
  19. package/dist/{chunk-U4BZKCBH.js → chunk-Z6ZHXO2R.js} +4 -4
  20. package/dist/hooks/index.js +4 -4
  21. package/dist/index.js +10 -11
  22. package/dist/index.native.js +10 -11
  23. package/dist/index.web.js +9 -10
  24. package/dist/index.web.js.map +1 -1
  25. package/dist/with-auth/index.js +6 -7
  26. package/dist/with-auth/index.js.map +1 -1
  27. package/package.json +1 -1
  28. package/dist/UserMetadataContext-QLIv-mfF.d.ts +0 -171
  29. package/dist/chunk-5HJLTYRA.js +0 -355
  30. package/dist/chunk-5HJLTYRA.js.map +0 -1
  31. package/dist/chunk-6KN7KLEG.js +0 -1
  32. package/dist/chunk-7NFMEDJW.js.map +0 -1
  33. package/dist/chunk-NP34C3O3.js.map +0 -1
  34. package/dist/chunk-UBHORKBS.js.map +0 -1
  35. package/dist/chunk-YQUNORJD.js.map +0 -1
  36. /package/dist/{chunk-7P2LGZYQ.js.map → chunk-3UW5K5PL.js.map} +0 -0
  37. /package/dist/{chunk-X747EEWD.js.map → chunk-AQ5JJKIN.js.map} +0 -0
  38. /package/dist/{chunk-6KN7KLEG.js.map → chunk-NSIAAYW3.js.map} +0 -0
  39. /package/dist/{chunk-U4BZKCBH.js.map → chunk-Z6ZHXO2R.js.map} +0 -0
@@ -0,0 +1,33 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import { ReactNode } from 'react';
4
+ import { D as Database } from './useSupabase-DSZNeXnF.js';
5
+
6
+ type UserMetadataRow = Database["core"]["Tables"]["UserMetadata"]["Row"];
7
+ type UserMetadataInsert = Database["core"]["Tables"]["UserMetadata"]["Insert"];
8
+ type UserMetadataUpdate = Database["core"]["Tables"]["UserMetadata"]["Update"];
9
+ interface UserMetadataContextType {
10
+ metadata: Record<string, string>;
11
+ isLoading: boolean;
12
+ error: Error | null;
13
+ setMetadata: (key: string, value: string) => Promise<void>;
14
+ getMetadata: (key: string) => string | undefined;
15
+ removeMetadata: (key: string) => Promise<void>;
16
+ refreshMetadata: () => Promise<void>;
17
+ }
18
+ declare const userMetadataContext: react.Context<UserMetadataContextType>;
19
+ declare function UserMetadataProvider({ children }: {
20
+ children: ReactNode;
21
+ }): react_jsx_runtime.JSX.Element;
22
+ declare function useUserMetadata(): UserMetadataContextType;
23
+ declare function useUserMetadataValue(key: string): string | undefined;
24
+ declare function useSetUserMetadata(): {
25
+ setMetadata: (key: string, value: string) => Promise<void>;
26
+ removeMetadata: (key: string) => Promise<void>;
27
+ };
28
+ declare function useUserMetadataState<T>(key: string, defaultValue: T, options?: {
29
+ serialize?: (value: T) => string;
30
+ deserialize?: (value: string) => T;
31
+ }): [T, (value: T) => Promise<void>, boolean];
32
+
33
+ export { type UserMetadataContextType as U, useUserMetadata as a, useUserMetadataState as b, useUserMetadataValue as c, userMetadataContext as d, type UserMetadataInsert as e, UserMetadataProvider as f, type UserMetadataRow as g, type UserMetadataUpdate as h, useSetUserMetadata as u };
@@ -1,71 +1,17 @@
1
- export { j as SimpleAuthContextValue, S as SimpleAuthProvider, i as SimpleAuthProviderProps, k as SimpleProfile, P as SimpleProfileStatus, l as SimpleUserAccess, U as UserMetadataContextType, r as UserMetadataInsert, s as UserMetadataProvider, t as UserMetadataRow, v as UserMetadataUpdate, g as getPermissionLevel, h as hasResourceAccess, a as useRequireAuth, b as useResourceAccess, m as useSetUserMetadata, u as useSimpleAuth, e as useSimpleCanDelete, d as useSimpleCanEdit, f as useSimpleCanShare, c as useSimpleCanView, n as useUserMetadata, o as useUserMetadataState, p as useUserMetadataValue, q as userMetadataContext } from '../UserMetadataContext-QLIv-mfF.js';
1
+ export { P as Profile, a as ProfileStatus, S as SetupAuthContext, b as SetupAuthContextProviderProps, s as setupAuthContext } from '../setupAuthContext-B76nbIP6.js';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
3
  import * as react from 'react';
4
4
  import { ReactNode } from 'react';
5
- import { User } from '@supabase/supabase-js';
6
- export { P as Profile, a as ProfileStatus, S as SetupAuthContext, b as SetupAuthContextProviderProps, s as setupAuthContext } from '../setupAuthContext-B76nbIP6.js';
7
5
  import { d as EntityType, b as EntityPermissionCheck, a as EntityAction } from '../EntityPermissions-DwFt4tUd.js';
6
+ export { U as UserMetadataContextType, e as UserMetadataInsert, f as UserMetadataProvider, g as UserMetadataRow, h as UserMetadataUpdate, u as useSetUserMetadata, a as useUserMetadata, b as useUserMetadataState, c as useUserMetadataValue, d as userMetadataContext } from '../UserMetadataContext-yLZQu24J.js';
7
+ import '@supabase/supabase-js';
8
8
  import '../useSupabase-DSZNeXnF.js';
9
9
  import '@supabase/supabase-js/dist/module/lib/types.js';
10
10
 
11
- interface PowerSyncDB {
12
- getAll: <T>(sql: string, params?: any[]) => Promise<T[]>;
13
- getOptional: <T>(sql: string, params?: any[]) => Promise<T | null>;
14
- watch: (sql: string, params: any[], options: {
15
- onResult: (result: any) => void;
16
- }, abortOptions?: {
17
- signal: AbortSignal;
18
- }) => void;
19
- }
20
- interface SupabaseClient {
21
- auth: {
22
- getUser: () => Promise<{
23
- data: {
24
- user: User | null;
25
- };
26
- error: any;
27
- }>;
28
- getSession: () => Promise<{
29
- data: {
30
- session: {
31
- user: User;
32
- } | null;
33
- };
34
- error: any;
35
- }>;
36
- signOut: () => Promise<{
37
- error: any;
38
- }>;
39
- onAuthStateChange: (callback: (event: string, session: any) => void) => {
40
- data: {
41
- subscription: {
42
- unsubscribe: () => void;
43
- };
44
- };
45
- };
46
- };
47
- }
48
- interface OfflineAuthProviderProps {
49
- children: ReactNode;
50
- /** PowerSync database instance */
51
- db: PowerSyncDB | null;
52
- /** Supabase client for auth */
53
- supabase: SupabaseClient;
54
- /** Whether PowerSync is ready */
55
- isDbReady?: boolean;
56
- }
57
- declare function OfflineAuthProvider({ children, db, supabase, isDbReady, }: OfflineAuthProviderProps): react_jsx_runtime.JSX.Element;
58
-
59
11
  interface AuthProviderProps {
60
12
  children: ReactNode;
61
- /**
62
- * Enable entity-level permissions system (Project, Client, ProjectDatabase access control).
63
- * When enabled, wraps children with PermissionProvider.
64
- * @default false
65
- */
66
- enableEntityPermissions?: boolean;
67
13
  }
68
- declare function AuthProvider({ children, enableEntityPermissions, }: AuthProviderProps): react_jsx_runtime.JSX.Element;
14
+ declare function AuthProvider({ children }: AuthProviderProps): react_jsx_runtime.JSX.Element;
69
15
 
70
16
  interface EntityIdentifier {
71
17
  entityType: EntityType;
@@ -93,4 +39,4 @@ declare function PermissionProvider({ children }: {
93
39
  }): react_jsx_runtime.JSX.Element;
94
40
  declare function usePermissions(): PermissionContextValue;
95
41
 
96
- export { AuthProvider, type AuthProviderProps, type EntityPermissionContextValue, OfflineAuthProvider, type OfflineAuthProviderProps, type PermissionContextValue, PermissionProvider, entityPermissionContext, permissionContext, usePermissions };
42
+ export { AuthProvider, type AuthProviderProps, type EntityPermissionContextValue, type PermissionContextValue, PermissionProvider, entityPermissionContext, permissionContext, usePermissions };
@@ -1,16 +1,3 @@
1
- import {
2
- OfflineAuthProvider,
3
- SimpleAuthProvider,
4
- getPermissionLevel,
5
- hasResourceAccess,
6
- useCanDelete,
7
- useCanEdit,
8
- useCanShare,
9
- useCanView,
10
- useRequireAuth,
11
- useResourceAccess,
12
- useSimpleAuth
13
- } from "../chunk-5HJLTYRA.js";
14
1
  import {
15
2
  AuthProvider,
16
3
  PermissionProvider,
@@ -24,8 +11,8 @@ import {
24
11
  useUserMetadataState,
25
12
  useUserMetadataValue,
26
13
  userMetadataContext
27
- } from "../chunk-YQUNORJD.js";
28
- import "../chunk-UBHORKBS.js";
14
+ } from "../chunk-MZLEDWJF.js";
15
+ import "../chunk-5SJ5O2NQ.js";
29
16
  import "../chunk-J4ZVCXZ4.js";
30
17
  import "../chunk-YUX6RGLZ.js";
31
18
  import "../chunk-AKIRHA4Q.js";
@@ -33,24 +20,13 @@ import "../chunk-DMVUEJG2.js";
33
20
  import "../chunk-7D4SUZUM.js";
34
21
  export {
35
22
  AuthProvider,
36
- OfflineAuthProvider,
37
23
  PermissionProvider,
38
- SimpleAuthProvider,
39
24
  UserMetadataProvider,
40
25
  entityPermissionContext,
41
- getPermissionLevel,
42
- hasResourceAccess,
43
26
  permissionContext,
44
27
  setupAuthContext,
45
28
  usePermissions,
46
- useRequireAuth,
47
- useResourceAccess,
48
29
  useSetUserMetadata,
49
- useSimpleAuth,
50
- useCanDelete as useSimpleCanDelete,
51
- useCanEdit as useSimpleCanEdit,
52
- useCanShare as useSimpleCanShare,
53
- useCanView as useSimpleCanView,
54
30
  useUserMetadata,
55
31
  useUserMetadataState,
56
32
  useUserMetadataValue,
@@ -1,116 +1,12 @@
1
1
  import { User } from '@supabase/supabase-js';
2
- import { k as SimpleProfile, l as SimpleUserAccess } from '../UserMetadataContext-QLIv-mfF.js';
3
- export { m as useSetUserMetadata, n as useUserMetadata, o as useUserMetadataState, p as useUserMetadataValue } from '../UserMetadataContext-QLIv-mfF.js';
4
2
  import { S as SetupAuthContext, E as EffectivePermission } from '../setupAuthContext-B76nbIP6.js';
5
3
  import { d as EntityType, a as EntityAction, b as EntityPermissionCheck } from '../EntityPermissions-DwFt4tUd.js';
6
- import 'react/jsx-runtime';
4
+ export { u as useSetUserMetadata, a as useUserMetadata, b as useUserMetadataState, c as useUserMetadataValue } from '../UserMetadataContext-yLZQu24J.js';
7
5
  import 'react';
6
+ import 'react/jsx-runtime';
8
7
  import '../useSupabase-DSZNeXnF.js';
9
8
  import '@supabase/supabase-js/dist/module/lib/types.js';
10
9
 
11
- /**
12
- * useOfflineAuth - Hook for offline-first authentication
13
- *
14
- * Reads Profile and UserAccess from PowerSync (local SQLite).
15
- * Works 100% offline once data is synced.
16
- *
17
- * Usage:
18
- * ```tsx
19
- * import { SimpleAuthProvider } from "@pol-studios/db";
20
- * import { useOfflineAuth } from "@pol-studios/db";
21
- *
22
- * function AuthWrapper({ children }) {
23
- * const authData = useOfflineAuth();
24
- *
25
- * return (
26
- * <SimpleAuthProvider {...authData}>
27
- * {children}
28
- * </SimpleAuthProvider>
29
- * );
30
- * }
31
- * ```
32
- */
33
-
34
- interface OfflineAuthData {
35
- /** Supabase user from auth session */
36
- user: User | null;
37
- /** Profile from PowerSync */
38
- profile: SimpleProfile | null;
39
- /** User access records from PowerSync */
40
- userAccess: SimpleUserAccess[] | null;
41
- /** Whether auth data is loading */
42
- isLoading: boolean;
43
- /** Sign out function */
44
- onSignOut: () => Promise<void>;
45
- }
46
- interface UseOfflineAuthOptions {
47
- /** Supabase client for auth operations */
48
- supabase: {
49
- auth: {
50
- getUser: () => Promise<{
51
- data: {
52
- user: User | null;
53
- };
54
- error: any;
55
- }>;
56
- signOut: () => Promise<{
57
- error: any;
58
- }>;
59
- onAuthStateChange: (callback: (event: string, session: any) => void) => {
60
- data: {
61
- subscription: {
62
- unsubscribe: () => void;
63
- };
64
- };
65
- };
66
- };
67
- };
68
- /** PowerSync database for local queries */
69
- db: {
70
- getAll: <T>(sql: string, params?: any[]) => Promise<T[]>;
71
- getOptional: <T>(sql: string, params?: any[]) => Promise<T | null>;
72
- } | null;
73
- /** Whether PowerSync is ready */
74
- isDbReady?: boolean;
75
- }
76
- /**
77
- * Query keys for React Query integration
78
- */
79
- declare const offlineAuthQueryKeys: {
80
- profile: (userId: string | undefined) => readonly ["profile", string];
81
- userAccess: (userId: string | undefined) => readonly ["userAccess", string];
82
- };
83
- /**
84
- * Query functions for React Query integration.
85
- * Use these with useQuery from @tanstack/react-query.
86
- *
87
- * @example
88
- * ```tsx
89
- * import { useQuery } from "@tanstack/react-query";
90
- * import { offlineAuthQueries, offlineAuthQueryKeys } from "@pol-studios/db";
91
- *
92
- * function useProfile(db, userId) {
93
- * return useQuery({
94
- * queryKey: offlineAuthQueryKeys.profile(userId),
95
- * queryFn: () => offlineAuthQueries.fetchProfile(db, userId),
96
- * enabled: !!userId && !!db,
97
- * });
98
- * }
99
- * ```
100
- */
101
- declare const offlineAuthQueries: {
102
- fetchProfile(db: {
103
- getOptional: <T>(sql: string, params?: any[]) => Promise<T | null>;
104
- }, userId: string): Promise<SimpleProfile | null>;
105
- fetchUserAccess(db: {
106
- getAll: <T>(sql: string, params?: any[]) => Promise<T[]>;
107
- }, userId: string): Promise<SimpleUserAccess[]>;
108
- };
109
- /**
110
- * Extract access keys from UserAccess records.
111
- */
112
- declare function extractAccessKeys(userAccess: SimpleUserAccess[] | null): string[];
113
-
114
10
  /**
115
11
  * Hook for authenticated users only.
116
12
  * Throws an error if the user is not authenticated.
@@ -414,4 +310,4 @@ declare function useInvalidatePermission(): (entityType: EntityType, entityId: n
414
310
  */
415
311
  declare function usePermissionLoading(): boolean;
416
312
 
417
- export { EntityAction, EntityPermissionCheck, EntityType, type EntityWithPermission, type OfflineAuthData, type UseOfflineAuthOptions, extractAccessKeys, offlineAuthQueries, offlineAuthQueryKeys, useAuth, useCanCreate, useCanDelete, useCanEdit, useCanShare, useCanView, useInvalidatePermission, usePermission, usePermissionCheck, usePermissionLoading, usePermissionsBatch, useSetupAuth };
313
+ export { EntityAction, EntityPermissionCheck, EntityType, type EntityWithPermission, useAuth, useCanCreate, useCanDelete, useCanEdit, useCanShare, useCanView, useInvalidatePermission, usePermission, usePermissionCheck, usePermissionLoading, usePermissionsBatch, useSetupAuth };
@@ -1,7 +1,4 @@
1
1
  import {
2
- extractAccessKeys,
3
- offlineAuthQueries,
4
- offlineAuthQueryKeys,
5
2
  useAuth,
6
3
  useCanCreate,
7
4
  useCanDelete,
@@ -14,23 +11,20 @@ import {
14
11
  usePermissionLoading,
15
12
  usePermissionsBatch,
16
13
  useSetupAuth
17
- } from "../chunk-7NFMEDJW.js";
14
+ } from "../chunk-D7UZEYKO.js";
18
15
  import {
19
16
  useSetUserMetadata,
20
17
  useUserMetadata,
21
18
  useUserMetadataState,
22
19
  useUserMetadataValue
23
- } from "../chunk-YQUNORJD.js";
24
- import "../chunk-UBHORKBS.js";
20
+ } from "../chunk-MZLEDWJF.js";
21
+ import "../chunk-5SJ5O2NQ.js";
25
22
  import "../chunk-J4ZVCXZ4.js";
26
23
  import "../chunk-YUX6RGLZ.js";
27
24
  import "../chunk-AKIRHA4Q.js";
28
25
  import "../chunk-DMVUEJG2.js";
29
26
  import "../chunk-7D4SUZUM.js";
30
27
  export {
31
- extractAccessKeys,
32
- offlineAuthQueries,
33
- offlineAuthQueryKeys,
34
28
  useAuth,
35
29
  useCanCreate,
36
30
  useCanDelete,
@@ -1,11 +1,11 @@
1
- export { j as SimpleAuthContextValue, S as SimpleAuthProvider, i as SimpleAuthProviderProps, k as SimpleProfile, P as SimpleProfileStatus, l as SimpleUserAccess, U as UserMetadataContextType, r as UserMetadataInsert, s as UserMetadataProvider, t as UserMetadataRow, v as UserMetadataUpdate, g as getPermissionLevel, h as hasResourceAccess, a as useRequireAuth, b as useResourceAccess, m as useSetUserMetadata, u as useSimpleAuth, e as useSimpleCanDelete, d as useSimpleCanEdit, f as useSimpleCanShare, c as useSimpleCanView, n as useUserMetadata, o as useUserMetadataState, p as useUserMetadataValue, q as userMetadataContext } from '../UserMetadataContext-QLIv-mfF.js';
2
- export { EntityWithPermission, OfflineAuthData, UseOfflineAuthOptions, extractAccessKeys, offlineAuthQueries, offlineAuthQueryKeys, useAuth, useCanCreate, useCanDelete, useCanEdit, useCanShare, useCanView, useInvalidatePermission, usePermission, usePermissionCheck, usePermissionLoading, usePermissionsBatch, useSetupAuth } from './hooks.js';
3
- export { AuthProvider, AuthProviderProps, EntityPermissionContextValue, OfflineAuthProvider, OfflineAuthProviderProps, PermissionContextValue, PermissionProvider, entityPermissionContext, permissionContext, usePermissions } from './context.js';
1
+ export { EntityWithPermission, useAuth, useCanCreate, useCanDelete, useCanEdit, useCanShare, useCanView, useInvalidatePermission, usePermission, usePermissionCheck, usePermissionLoading, usePermissionsBatch, useSetupAuth } from './hooks.js';
4
2
  export { P as Profile, a as ProfileStatus, S as SetupAuthContext, b as SetupAuthContextProviderProps, s as setupAuthContext } from '../setupAuthContext-B76nbIP6.js';
3
+ export { AuthProvider, AuthProviderProps, EntityPermissionContextValue, PermissionContextValue, PermissionProvider, entityPermissionContext, permissionContext, usePermissions } from './context.js';
4
+ export { U as UserMetadataContextType, e as UserMetadataInsert, f as UserMetadataProvider, g as UserMetadataRow, h as UserMetadataUpdate, u as useSetUserMetadata, a as useUserMetadata, b as useUserMetadataState, c as useUserMetadataValue, d as userMetadataContext } from '../UserMetadataContext-yLZQu24J.js';
5
5
  export { hasAccess, hasAllAccess, hasAllEntityAccess, hasAnyAccess, hasAnyEntityAccess, hasEntityAccess, isEntityAccessDenied, isPermissionLoaded } from './guards.js';
6
6
  export { E as EntityAccessRecord, a as EntityAction, b as EntityPermissionCheck, c as EntityPermissionLevel, d as EntityType, P as PermissionEffect } from '../EntityPermissions-DwFt4tUd.js';
7
- import 'react/jsx-runtime';
8
- import 'react';
9
7
  import '@supabase/supabase-js';
8
+ import 'react';
9
+ import 'react/jsx-runtime';
10
10
  import '../useSupabase-DSZNeXnF.js';
11
11
  import '@supabase/supabase-js/dist/module/lib/types.js';
@@ -1,34 +1,18 @@
1
- import "../chunk-6KN7KLEG.js";
1
+ import "../chunk-NSIAAYW3.js";
2
2
  import {
3
- OfflineAuthProvider,
4
- SimpleAuthProvider,
5
- getPermissionLevel,
6
- hasResourceAccess,
3
+ useAuth,
4
+ useCanCreate,
7
5
  useCanDelete,
8
6
  useCanEdit,
9
7
  useCanShare,
10
8
  useCanView,
11
- useRequireAuth,
12
- useResourceAccess,
13
- useSimpleAuth
14
- } from "../chunk-5HJLTYRA.js";
15
- import {
16
- extractAccessKeys,
17
- offlineAuthQueries,
18
- offlineAuthQueryKeys,
19
- useAuth,
20
- useCanCreate,
21
- useCanDelete as useCanDelete2,
22
- useCanEdit as useCanEdit2,
23
- useCanShare as useCanShare2,
24
- useCanView as useCanView2,
25
9
  useInvalidatePermission,
26
10
  usePermission,
27
11
  usePermissionCheck,
28
12
  usePermissionLoading,
29
13
  usePermissionsBatch,
30
14
  useSetupAuth
31
- } from "../chunk-7NFMEDJW.js";
15
+ } from "../chunk-D7UZEYKO.js";
32
16
  import {
33
17
  AuthProvider,
34
18
  PermissionProvider,
@@ -42,8 +26,8 @@ import {
42
26
  useUserMetadataState,
43
27
  useUserMetadataValue,
44
28
  userMetadataContext
45
- } from "../chunk-YQUNORJD.js";
46
- import "../chunk-UBHORKBS.js";
29
+ } from "../chunk-MZLEDWJF.js";
30
+ import "../chunk-5SJ5O2NQ.js";
47
31
  import {
48
32
  hasAccess,
49
33
  hasAllAccess,
@@ -61,47 +45,33 @@ import "../chunk-DMVUEJG2.js";
61
45
  import "../chunk-7D4SUZUM.js";
62
46
  export {
63
47
  AuthProvider,
64
- OfflineAuthProvider,
65
48
  PermissionProvider,
66
- SimpleAuthProvider,
67
49
  UserMetadataProvider,
68
50
  entityPermissionContext,
69
- extractAccessKeys,
70
- getPermissionLevel,
71
51
  hasAccess,
72
52
  hasAllAccess,
73
53
  hasAllEntityAccess,
74
54
  hasAnyAccess,
75
55
  hasAnyEntityAccess,
76
56
  hasEntityAccess,
77
- hasResourceAccess,
78
57
  isEntityAccessDenied,
79
58
  isPermissionLoaded,
80
- offlineAuthQueries,
81
- offlineAuthQueryKeys,
82
59
  permissionContext,
83
60
  setupAuthContext,
84
61
  useAuth,
85
62
  useCanCreate,
86
- useCanDelete2 as useCanDelete,
87
- useCanEdit2 as useCanEdit,
88
- useCanShare2 as useCanShare,
89
- useCanView2 as useCanView,
63
+ useCanDelete,
64
+ useCanEdit,
65
+ useCanShare,
66
+ useCanView,
90
67
  useInvalidatePermission,
91
68
  usePermission,
92
69
  usePermissionCheck,
93
70
  usePermissionLoading,
94
71
  usePermissions,
95
72
  usePermissionsBatch,
96
- useRequireAuth,
97
- useResourceAccess,
98
73
  useSetUserMetadata,
99
74
  useSetupAuth,
100
- useSimpleAuth,
101
- useCanDelete as useSimpleCanDelete,
102
- useCanEdit as useSimpleCanEdit,
103
- useCanShare as useSimpleCanShare,
104
- useCanView as useSimpleCanView,
105
75
  useUserMetadata,
106
76
  useUserMetadataState,
107
77
  useUserMetadataValue,
@@ -3,12 +3,12 @@ import {
3
3
  createAdapterRegistry,
4
4
  createSupabaseAdapter,
5
5
  stripSchemaPrefix
6
- } from "./chunk-X747EEWD.js";
6
+ } from "./chunk-AQ5JJKIN.js";
7
7
  import {
8
8
  DataLayerContext,
9
9
  DataLayerCoreContext,
10
10
  DataLayerStatusContext
11
- } from "./chunk-UBHORKBS.js";
11
+ } from "./chunk-5SJ5O2NQ.js";
12
12
  import {
13
13
  QueryExecutor,
14
14
  extractRelationNames,
@@ -4952,4 +4952,4 @@ object-assign/index.js:
4952
4952
  @license MIT
4953
4953
  *)
4954
4954
  */
4955
- //# sourceMappingURL=chunk-7P2LGZYQ.js.map
4955
+ //# sourceMappingURL=chunk-3UW5K5PL.js.map
@@ -199,6 +199,78 @@ function useDbQuery(table, options = {}) {
199
199
  };
200
200
  }
201
201
 
202
+ // src/hooks/useDbQueryById.ts
203
+ import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo2 } from "react";
204
+ import { useQuery as useQuery2 } from "@tanstack/react-query";
205
+ function buildQueryKey2(table, id, select) {
206
+ return ["v3", "queryById", table, id, select ?? "*"];
207
+ }
208
+ function useDbQueryById(table, id, options = {}) {
209
+ const {
210
+ registry
211
+ } = useDataLayerCore();
212
+ const {
213
+ select,
214
+ enabled = id != null,
215
+ staleTime = 3e4
216
+ } = options;
217
+ const adapter = useMemo2(() => {
218
+ try {
219
+ return registry.getAdapter(table);
220
+ } catch {
221
+ return null;
222
+ }
223
+ }, [registry, table]);
224
+ const queryKey = useMemo2(() => buildQueryKey2(table, id, select), [table, id, select]);
225
+ const queryFn = useCallback2(async () => {
226
+ if (!adapter) {
227
+ throw new Error(`Adapter not available for table: ${table}`);
228
+ }
229
+ if (id == null) {
230
+ return null;
231
+ }
232
+ if (adapter.queryById) {
233
+ return adapter.queryById(table, String(id), {
234
+ select
235
+ });
236
+ }
237
+ const result = await adapter.query(table, {
238
+ select,
239
+ where: {
240
+ id
241
+ },
242
+ limit: 1
243
+ });
244
+ return result.data[0] ?? null;
245
+ }, [adapter, table, id, select]);
246
+ const query = useQuery2({
247
+ queryKey,
248
+ queryFn,
249
+ enabled: enabled && adapter !== null && id != null,
250
+ staleTime
251
+ });
252
+ useEffect2(() => {
253
+ const adapterName = adapter?.name ?? "unknown";
254
+ if (query.isError && query.error) {
255
+ devWarn("useDbQueryById", `${table}(${id}) via ${adapterName}: Error - ${query.error.message}`);
256
+ }
257
+ if (query.isSuccess && query.data === null) {
258
+ devLog("useDbQueryById", `${table}(${id}) via ${adapterName}: not found`);
259
+ }
260
+ }, [query.isError, query.error, query.isSuccess, query.data, table, id, adapter]);
261
+ const refetch = useCallback2(async () => {
262
+ await query.refetch();
263
+ }, [query]);
264
+ return {
265
+ data: query.data,
266
+ isLoading: query.isLoading,
267
+ isPending: query.isPending,
268
+ isFetching: query.isFetching,
269
+ error: query.error,
270
+ refetch
271
+ };
272
+ }
273
+
202
274
  export {
203
275
  DataLayerCoreContext,
204
276
  DataLayerStatusContext,
@@ -210,6 +282,7 @@ export {
210
282
  useDataLayerOptional,
211
283
  devLog,
212
284
  devWarn,
213
- useDbQuery
285
+ useDbQuery,
286
+ useDbQueryById
214
287
  };
215
- //# sourceMappingURL=chunk-UBHORKBS.js.map
288
+ //# sourceMappingURL=chunk-5SJ5O2NQ.js.map