@pol-studios/db 1.0.38 → 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.
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/errors/TimeoutError.ts","../src/useDbQuery.ts","../src/auth/context/setupAuthContext.tsx","../src/auth/context/PermissionContext.tsx","../src/auth/context/AuthProvider.tsx","../src/auth/context/UserMetadataContext.tsx","../src/useDbUpsert.ts"],"sourcesContent":["export const TIMEOUT_ERROR_MESSAGE = \"Request timed out\";\nexport const DEFAULT_QUERY_TIMEOUT = 15_000; // 15 seconds\n\nexport function isTimeoutError(error: Error | null | undefined): boolean {\n if (!error) return false;\n return error.name === \"AbortError\" || error.message === TIMEOUT_ERROR_MESSAGE || error.message.toLowerCase().includes(\"timed out\");\n}","import { PostgrestError, PostgrestSingleResponse } from \"@supabase/supabase-js\";\nimport { useMemo, useRef } from \"react\";\nimport { ItemType } from \"@pol-studios/utils\";\nimport { encode, UseQuerySingleReturn } from \"@supabase-cache-helpers/postgrest-react-query\";\nimport { omit } from \"@pol-studios/utils\";\nimport { useQuery, UseQueryOptions } from \"@tanstack/react-query\";\nimport { useDelayedValue } from \"@pol-studios/hooks/state\";\nimport { DEFAULT_QUERY_TIMEOUT, TIMEOUT_ERROR_MESSAGE } from \"./errors/TimeoutError\";\ntype ConfigurationOptions<T> = {\n crossOrganization?: boolean;\n filter?: (item: ItemType<T>) => boolean;\n timeout?: number;\n};\nexport type UseDbQuerySingleReturn<T> = UseQuerySingleReturn<T> & {\n data: T | null | undefined;\n count?: number | null;\n};\nexport function useDbQuery<Result>(query: PromiseLike<PostgrestSingleResponse<Result>> & {\n abortSignal?: (signal: AbortSignal) => PromiseLike<PostgrestSingleResponse<Result>>;\n}, config?: Omit<UseQueryOptions<Result, PostgrestError>, \"queryKey\" | \"queryFn\"> & ConfigurationOptions<Result>) {\n // Debounce query key to prevent rapid query churn during fast navigation\n const queryKey = encode(query, false);\n const queryKeyString = queryKey.join(\"-\");\n const debouncedKeyString = useDelayedValue(queryKeyString, 50);\n\n // Only enable query when key has stabilized (debounced matches current)\n const isKeyStable = queryKeyString === debouncedKeyString;\n const effectiveEnabled = config?.enabled !== false && isKeyStable;\n const timeoutMs = config?.timeout ?? DEFAULT_QUERY_TIMEOUT;\n\n // Track count from Supabase response (for queries with count: \"exact\")\n const countRef = useRef<number | null>(null);\n const request = useQuery(useMemo(() => ({\n queryKey,\n queryFn: async ({\n signal\n }) => {\n const controller = new AbortController();\n signal.addEventListener(\"abort\", () => controller.abort());\n const timeoutId = setTimeout(() => controller.abort(), timeoutMs);\n try {\n // Execute query with abort signal\n const queryWithSignal = query.abortSignal?.(controller.signal) ?? query;\n const result = await queryWithSignal;\n if (result.error) throw result.error;\n // Store count if available (from queries with count: \"exact\")\n countRef.current = result.count ?? null;\n return result.data;\n } catch (err: any) {\n if (err.name === \"AbortError\") {\n throw new Error(TIMEOUT_ERROR_MESSAGE);\n }\n throw err;\n } finally {\n clearTimeout(timeoutId);\n }\n },\n ...omit({\n retry: 1,\n ...config,\n enabled: effectiveEnabled\n }, [\"queryKey\", \"timeout\"])\n }), [queryKey, config, effectiveEnabled, timeoutMs, query]));\n\n // Return request with count property added\n return useMemo(() => ({\n ...request,\n count: countRef.current\n }), [request, countRef.current]) as UseDbQuerySingleReturn<Result>;\n}","/**\n * SetupAuthContext - Shared context for auth state\n *\n * This file is separate to avoid circular dependencies between\n * AuthProvider and PermissionContext.\n */\n\nimport { createContext, ReactNode } from \"react\";\nimport { AuthTokenResponsePassword, SignUpWithPasswordCredentials, User } from \"@supabase/supabase-js\";\nexport type ProfileStatus = \"active\" | \"archived\" | \"suspended\";\n\n/**\n * Represents an effective permission for a user on a specific resource.\n * These are eagerly loaded at login for fast permission checks.\n */\nexport interface EffectivePermission {\n /** The type of resource (e.g., 'project', 'client', 'database') */\n resourceType: string;\n /** The ID of the specific resource */\n resourceId: string;\n /** The permission action (e.g., 'view', 'edit', 'admin') */\n permission: string;\n /** Numeric level for comparison: view=1, edit=2, admin=3 */\n permissionLevel: number;\n /** How the permission was granted */\n source: \"direct\" | \"group\" | \"inherited\";\n /** If inherited, from which resource */\n inheritedFrom: string | null;\n /** When the permission expires, if applicable */\n expiresAt: string | null;\n}\nexport interface SetupAuthContext {\n user?: User | null | undefined;\n isLoading: boolean;\n profile: Profile | null | undefined;\n access: string[];\n /** Eagerly loaded effective permissions for the user */\n effectivePermissions: EffectivePermission[];\n /** Whether the profile is archived */\n isArchived: boolean;\n /** Whether the profile is suspended */\n isSuspended: boolean;\n /** The profile status (active, archived, suspended) */\n profileStatus: ProfileStatus | undefined;\n registerAsync: (register: SignUpWithPasswordCredentials) => Promise<any>;\n signInAsync: (username: string, password: string) => Promise<AuthTokenResponsePassword>;\n signOutAsync: () => Promise<any>;\n refreshAsync: () => Promise<void>;\n onSignOut: (action: () => any) => string;\n removeOnSignOut: (id: string) => any;\n hasAccess?: (key: string) => boolean;\n}\n\n// Profile type - simplified version, the full type is in AuthProvider\nexport interface Profile {\n id: string;\n email?: string;\n fullName?: string;\n status?: ProfileStatus;\n UserAccess?: Array<{\n accessKey: string;\n }>;\n [key: string]: any;\n}\nexport const setupAuthContext = createContext({} as SetupAuthContext);\n\n/**\n * Props for SetupAuthContextProvider\n * A simpler provider that takes pre-computed auth state\n */\nexport interface SetupAuthContextProviderProps {\n children: ReactNode;\n auth: SetupAuthContext;\n}","import { createContext, ReactNode, useCallback, useContext, useEffect, useMemo, useRef, useState } from \"react\";\nimport useSupabase from \"../../useSupabase\";\nimport { setupAuthContext } from \"./setupAuthContext\";\nimport { EntityType, EntityPermissionLevel, EntityAction, EntityPermissionCheck } from \"../types/EntityPermissions\";\n\n// Cache entry with TTL\ninterface CacheEntry {\n permission: EntityPermissionCheck;\n expiresAt: number;\n}\n\n// Entity identifier for batch lookups\ninterface EntityIdentifier {\n entityType: EntityType;\n entityId: number;\n}\n\n// Cache key helper\nfunction getCacheKey(userId: string | undefined, entityType: EntityType, entityId: number): string {\n return `${userId || \"anon\"}:${entityType}:${entityId}`;\n}\n\n// Default loading state\nconst loadingPermission: EntityPermissionCheck = {\n canView: false,\n canAdminView: false,\n canEdit: false,\n canCreate: false,\n canDelete: false,\n canShare: false,\n permissionLevel: null,\n isLoading: true\n};\n\n// No permission state\nconst noPermission: EntityPermissionCheck = {\n canView: false,\n canAdminView: false,\n canEdit: false,\n canCreate: false,\n canDelete: false,\n canShare: false,\n permissionLevel: null,\n isLoading: false,\n isDenied: false\n};\n\n// Denied permission state - explicitly blocked access\nconst deniedPermission: EntityPermissionCheck = {\n canView: false,\n canAdminView: false,\n canEdit: false,\n canCreate: false,\n canDelete: false,\n canShare: false,\n permissionLevel: null,\n isLoading: false,\n isDenied: true\n};\n\n// Map permission level to permission check\n// If permission is 'denied', it means access was explicitly blocked\n// Handles both legacy formats (ReadOnly, AdminReadOnly, ReadWrite, Admin)\n// and new formats (view, edit, admin, denied)\nfunction mapPermissionLevel(level: EntityPermissionLevel | \"denied\" | string | null): EntityPermissionCheck {\n if (!level) {\n return noPermission;\n }\n\n // Normalize to lowercase for comparison to handle both legacy and new formats\n const normalizedLevel = level.toLowerCase();\n switch (normalizedLevel) {\n // Legacy format: ReadOnly, New format: view\n case \"readonly\":\n case \"view\":\n return {\n canView: true,\n canAdminView: false,\n canEdit: false,\n canCreate: false,\n canDelete: false,\n canShare: false,\n permissionLevel: \"ReadOnly\",\n isLoading: false,\n isDenied: false\n };\n // Legacy format: AdminReadOnly (no new equivalent, keep for backwards compatibility)\n case \"adminreadonly\":\n return {\n canView: true,\n canAdminView: true,\n canEdit: false,\n canCreate: false,\n canDelete: false,\n canShare: false,\n permissionLevel: \"AdminReadOnly\",\n isLoading: false,\n isDenied: false\n };\n // Legacy format: ReadWrite, New format: edit\n case \"readwrite\":\n case \"edit\":\n return {\n canView: true,\n canAdminView: false,\n canEdit: true,\n canCreate: true,\n canDelete: false,\n canShare: false,\n permissionLevel: \"ReadWrite\",\n isLoading: false,\n isDenied: false\n };\n // Legacy format: Admin, New format: admin\n case \"admin\":\n return {\n canView: true,\n canAdminView: true,\n canEdit: true,\n canCreate: true,\n canDelete: true,\n canShare: true,\n permissionLevel: \"Admin\",\n isLoading: false,\n isDenied: false\n };\n // New format: denied - explicit access denial\n case \"denied\":\n return deniedPermission;\n default:\n console.warn(`Unknown permission level: ${level}`);\n return noPermission;\n }\n}\n\n// Context interface\nexport interface PermissionContextValue {\n getPermission: (entityType: EntityType, entityId: number) => EntityPermissionCheck;\n checkPermission: (entityType: EntityType, entityId: number, action: EntityAction) => boolean;\n prefetchPermissions: (entities: EntityIdentifier[]) => Promise<void>;\n invalidatePermission: (entityType: EntityType, entityId: number) => void;\n isLoading: boolean;\n}\n\n/**\n * @deprecated Use permissionContext instead\n */\nexport interface EntityPermissionContextValue extends PermissionContextValue {}\nexport const permissionContext = createContext<PermissionContextValue>({} as PermissionContextValue);\n\n/**\n * @deprecated Use permissionContext instead\n */\nexport const entityPermissionContext = permissionContext;\n\n// TTL for cache entries (5 minutes)\nconst CACHE_TTL_MS = 5 * 60 * 1000;\n\n// TTL for error cache entries (30 seconds) - shorter to allow quick retry\nconst ERROR_CACHE_TTL_MS = 30 * 1000;\n\n// Batch collection delay (50ms)\nconst BATCH_DELAY_MS = 50;\nexport function PermissionProvider({\n children\n}: {\n children: ReactNode;\n}) {\n const supabase = useSupabase();\n const setupAuth = useContext(setupAuthContext);\n const user = setupAuth?.user;\n\n // Permission cache\n const cacheRef = useRef<Map<string, CacheEntry>>(new Map());\n\n // Pending lookups for batching\n const pendingLookupsRef = useRef<Set<string>>(new Set());\n\n // In-flight lookups to prevent duplicate requests during async RPC calls\n const inFlightRef = useRef<Set<string>>(new Set());\n\n // Batch timer ref\n const batchTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n // Loading state\n const [isLoading, setIsLoading] = useState(false);\n\n // Force re-render trigger\n const [, forceUpdate] = useState(0);\n\n // Clean up expired cache entries\n const cleanupExpiredEntries = useCallback(() => {\n const now = Date.now();\n const cache = cacheRef.current;\n let hasExpired = false;\n for (const [key, entry] of cache.entries()) {\n if (entry.expiresAt < now) {\n cache.delete(key);\n hasExpired = true;\n }\n }\n if (hasExpired) {\n forceUpdate(prev => prev + 1);\n }\n }, []);\n\n // Periodic cleanup of expired entries\n useEffect(() => {\n const cleanupInterval = setInterval(cleanupExpiredEntries, 60 * 1000);\n return () => clearInterval(cleanupInterval);\n }, [cleanupExpiredEntries]);\n\n // Execute batch lookup\n const executeBatchLookup = useCallback(async () => {\n const pending = Array.from(pendingLookupsRef.current);\n pendingLookupsRef.current.clear();\n if (pending.length === 0 || !user?.id) {\n return;\n }\n\n // Move pending keys to in-flight to prevent duplicate requests\n pending.forEach(k => inFlightRef.current.add(k));\n setIsLoading(true);\n try {\n // Parse pending keys back to entities (format: userId:entityType:entityId)\n const entities = pending.map(key_0 => {\n const parts = key_0.split(\":\");\n // Skip the userId part (index 0), use entityType (index 1) and entityId (index 2)\n const entityType = parts[1];\n const entityIdStr = parts[2];\n return {\n entity_type: entityType as EntityType,\n entity_id: parseInt(entityIdStr, 10)\n };\n });\n\n // Call RPC for batch lookup\n // Using 'as any' because the RPC function type isn't in the generated database types\n const {\n data,\n error\n } = await (supabase.rpc as any)(\"get_user_entity_permissions\", {\n p_user_id: user.id,\n p_entities: entities\n });\n if (error) {\n console.error(\"Failed to fetch entity permissions:\", error);\n // Mark all pending as no permission with shorter TTL to allow quick retry\n const cache_0 = cacheRef.current;\n const now_0 = Date.now();\n for (const key_1 of pending) {\n cache_0.set(key_1, {\n permission: noPermission,\n expiresAt: now_0 + ERROR_CACHE_TTL_MS\n });\n }\n } else if (data) {\n // Update cache with results\n const cache_1 = cacheRef.current;\n const now_1 = Date.now();\n\n // Create a map of results for quick lookup\n // Permission can be a standard level or 'denied' for explicit deny\n const resultsMap = new Map<string, EntityPermissionLevel | \"denied\">();\n // Type the data as an array of permission results\n const results = data as Array<{\n entity_type: EntityType;\n entity_id: number;\n permission: EntityPermissionLevel | \"denied\";\n }>;\n for (const result of results) {\n const key_2 = getCacheKey(user?.id, result.entity_type, result.entity_id);\n resultsMap.set(key_2, result.permission);\n }\n\n // Update cache for all pending keys\n for (const key_3 of pending) {\n const permissionLevel = resultsMap.get(key_3) || null;\n cache_1.set(key_3, {\n permission: mapPermissionLevel(permissionLevel),\n expiresAt: now_1 + CACHE_TTL_MS\n });\n }\n }\n forceUpdate(prev_0 => prev_0 + 1);\n } catch (err) {\n console.error(\"Unexpected error fetching entity permissions:\", err);\n } finally {\n // Remove from in-flight after completion (success or error)\n pending.forEach(k => inFlightRef.current.delete(k));\n setIsLoading(false);\n }\n }, [supabase, user?.id]);\n\n // Schedule batch lookup\n const scheduleBatchLookup = useCallback(() => {\n if (batchTimerRef.current) {\n clearTimeout(batchTimerRef.current);\n }\n batchTimerRef.current = setTimeout(() => {\n batchTimerRef.current = null;\n executeBatchLookup();\n }, BATCH_DELAY_MS);\n }, [executeBatchLookup]);\n\n // Get permission for an entity\n const getPermission = useCallback((entityType_0: EntityType, entityId: number): EntityPermissionCheck => {\n const key_4 = getCacheKey(user?.id, entityType_0, entityId);\n const cache_2 = cacheRef.current;\n const cached = cache_2.get(key_4);\n const now_2 = Date.now();\n\n // Return cached if valid\n if (cached && cached.expiresAt > now_2) {\n return cached.permission;\n }\n\n // Don't add if already pending or in-flight to prevent duplicate requests\n if (!pendingLookupsRef.current.has(key_4) && !inFlightRef.current.has(key_4)) {\n pendingLookupsRef.current.add(key_4);\n scheduleBatchLookup();\n }\n return loadingPermission;\n }, [scheduleBatchLookup, user?.id]);\n\n // Check specific permission action\n const checkPermission = useCallback((entityType_1: EntityType, entityId_0: number, action: EntityAction): boolean => {\n const permission = getPermission(entityType_1, entityId_0);\n if (permission.isLoading) {\n return false;\n }\n switch (action) {\n case \"view\":\n return permission.canView;\n case \"adminView\":\n return permission.canAdminView;\n case \"edit\":\n return permission.canEdit;\n case \"create\":\n return permission.canCreate;\n case \"delete\":\n return permission.canDelete;\n case \"share\":\n return permission.canShare;\n default:\n return false;\n }\n }, [getPermission]);\n\n // Prefetch permissions for multiple entities\n const prefetchPermissions = useCallback(async (entities_0: EntityIdentifier[]): Promise<void> => {\n if (!user?.id || entities_0.length === 0) {\n return;\n }\n const cache_3 = cacheRef.current;\n const now_3 = Date.now();\n\n // Filter out already cached entries, items already pending, and items in-flight\n const toFetch = entities_0.filter(entity => {\n const key_5 = getCacheKey(user?.id, entity.entityType, entity.entityId);\n const cached_0 = cache_3.get(key_5);\n const isPending = pendingLookupsRef.current.has(key_5);\n const isInFlight = inFlightRef.current.has(key_5);\n return !isPending && !isInFlight && (!cached_0 || cached_0.expiresAt <= now_3);\n });\n if (toFetch.length === 0) {\n return;\n }\n setIsLoading(true);\n try {\n const entitiesParam = toFetch.map(e => ({\n entity_type: e.entityType,\n entity_id: e.entityId\n }));\n\n // Using 'as any' because the RPC function type isn't in the generated database types\n const {\n data: data_0,\n error: error_0\n } = await (supabase.rpc as any)(\"get_user_entity_permissions\", {\n p_user_id: user.id,\n p_entities: entitiesParam\n });\n if (error_0) {\n console.error(\"Failed to prefetch entity permissions:\", error_0);\n return;\n }\n if (data_0) {\n // Capture timestamp AFTER the RPC call completes\n const cacheTimestamp = Date.now();\n\n // Permission can be a standard level or 'denied' for explicit deny\n const resultsMap_0 = new Map<string, EntityPermissionLevel | \"denied\">();\n // Type the data as an array of permission results\n const results_0 = data_0 as Array<{\n entity_type: EntityType;\n entity_id: number;\n permission: EntityPermissionLevel | \"denied\";\n }>;\n for (const result_0 of results_0) {\n const key_6 = getCacheKey(user?.id, result_0.entity_type, result_0.entity_id);\n resultsMap_0.set(key_6, result_0.permission);\n }\n for (const entity_0 of toFetch) {\n const key_7 = getCacheKey(user?.id, entity_0.entityType, entity_0.entityId);\n const permissionLevel_0 = resultsMap_0.get(key_7) || null;\n cache_3.set(key_7, {\n permission: mapPermissionLevel(permissionLevel_0),\n expiresAt: cacheTimestamp + CACHE_TTL_MS\n });\n }\n forceUpdate(prev_1 => prev_1 + 1);\n }\n } catch (err_0) {\n console.error(\"Unexpected error prefetching entity permissions:\", err_0);\n } finally {\n setIsLoading(false);\n }\n }, [supabase, user?.id]);\n\n // Invalidate a specific permission\n const invalidatePermission = useCallback((entityType_2: EntityType, entityId_1: number): void => {\n const key_8 = getCacheKey(user?.id, entityType_2, entityId_1);\n cacheRef.current.delete(key_8);\n forceUpdate(prev_2 => prev_2 + 1);\n }, [user?.id]);\n\n // Parse scoped access key format: <entity_type>:<entity_id>:<permission_level>\n // Returns null if the key format is invalid\n const parseScopedAccessKey = useCallback((key_9: string): {\n entityType: EntityType;\n entityId: number;\n } | null => {\n if (!key_9 || typeof key_9 !== \"string\") {\n return null;\n }\n const parts_0 = key_9.split(\":\");\n if (parts_0.length < 2) {\n return null;\n }\n const entityType_3 = parts_0[0];\n const entityId_2 = parseInt(parts_0[1], 10);\n if (isNaN(entityId_2)) {\n return null;\n }\n // Use explicit mapping instead of string manipulation\n // This correctly handles \"database\" -> \"ProjectDatabase\" case\n const entityTypeMap: Record<string, EntityType> = {\n client: \"Client\",\n project: \"Project\",\n database: \"ProjectDatabase\",\n projectdatabase: \"ProjectDatabase\"\n };\n const normalizedEntityType = entityTypeMap[entityType_3.toLowerCase()];\n if (!normalizedEntityType) {\n return null;\n }\n return {\n entityType: normalizedEntityType,\n entityId: entityId_2\n };\n }, []);\n\n // Real-time subscription for permission changes\n useEffect(() => {\n if (!user?.id) {\n return;\n }\n\n // Subscribe to changes on UserAccess table for the current user\n // Use unique channel name per user to avoid collisions\n const channel = supabase.channel(`entity-permissions-${user.id}`).on(\"postgres_changes\", {\n event: \"*\",\n schema: \"core\",\n table: \"UserAccess\",\n filter: `userId=eq.${user.id}`\n }, payload => {\n // Parse the scoped access key from the new record\n if (payload.new && typeof payload.new === \"object\" && \"scopedAccessKey\" in payload.new && typeof payload.new.scopedAccessKey === \"string\") {\n const parsed = parseScopedAccessKey(payload.new.scopedAccessKey);\n if (parsed) {\n invalidatePermission(parsed.entityType, parsed.entityId);\n }\n }\n // Parse the scoped access key from the old record (for deletes/updates)\n if (payload.old && typeof payload.old === \"object\" && \"scopedAccessKey\" in payload.old && typeof payload.old.scopedAccessKey === \"string\") {\n const parsed_0 = parseScopedAccessKey(payload.old.scopedAccessKey);\n if (parsed_0) {\n invalidatePermission(parsed_0.entityType, parsed_0.entityId);\n }\n }\n }).subscribe();\n return () => {\n channel.unsubscribe();\n supabase.removeChannel(channel);\n };\n }, [supabase, user?.id, invalidatePermission, parseScopedAccessKey]);\n\n // Clear cache on user change\n useEffect(() => {\n cacheRef.current.clear();\n pendingLookupsRef.current.clear();\n inFlightRef.current.clear();\n if (batchTimerRef.current) {\n clearTimeout(batchTimerRef.current);\n batchTimerRef.current = null;\n }\n forceUpdate(prev_3 => prev_3 + 1);\n }, [user?.id]);\n\n // Cleanup batch timer on unmount\n useEffect(() => {\n return () => {\n if (batchTimerRef.current) {\n clearTimeout(batchTimerRef.current);\n }\n };\n }, []);\n const value = useMemo(() => ({\n getPermission,\n checkPermission,\n prefetchPermissions,\n invalidatePermission,\n isLoading\n }), [getPermission, checkPermission, prefetchPermissions, invalidatePermission, isLoading]);\n return <permissionContext.Provider value={value}>\n {children}\n </permissionContext.Provider>;\n}\nexport function usePermissions() {\n const context = useContext(permissionContext);\n if (!context || Object.keys(context).length === 0) {\n throw new Error(\"usePermissions must be used within a PermissionProvider\");\n }\n return context;\n}","/**\n * AuthProvider - Unified auth provider for offline-first apps\n *\n * Features:\n * - Supabase auth with session timeout protection (3 second timeout)\n * - Profile and access data via useDbQuery (auto strategy: Supabase primary, PowerSync offline backup)\n * - Group-based access with permission levels (view=1, edit=2, admin=3)\n * - Wildcard matching (*:*:*, type:*:action, etc.)\n * - Works 100% offline once data is synced\n */\n\nimport { ReactNode, useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { User, SignUpWithPasswordCredentials } from \"@supabase/supabase-js\";\nimport { isUsable, newUuid } from \"@pol-studios/utils\";\nimport { useDbQuery } from \"../../hooks/useDbQuery\";\nimport useSupabase from \"../../useSupabase\";\nimport { PermissionProvider } from \"./PermissionContext\";\nimport { setupAuthContext, type ProfileStatus, type EffectivePermission } from \"./setupAuthContext\";\n\n// Re-export from shared context for API compatibility\nexport { setupAuthContext, type SetupAuthContext, type SetupAuthContextProviderProps, type ProfileStatus, type EffectivePermission } from \"./setupAuthContext\";\n\n// Session fetch timeout - fail fast to avoid loading hangs\nconst SESSION_FETCH_TIMEOUT_MS = 3000;\n\n// ============================================================================\n// Types for access-related tables\n// ============================================================================\n\ninterface ProfileRow {\n id: string;\n email?: string | null;\n firstName?: string | null;\n lastName?: string | null;\n fullName?: string | null;\n status?: ProfileStatus | null;\n profilePath?: string | null;\n [key: string]: unknown;\n}\ninterface UserAccessRow {\n id: string;\n accessKey: string;\n effect: string;\n expiresAt: string | null;\n userId: string;\n}\ninterface UserGroupRow {\n id: string;\n userId: string;\n groupId: number;\n expiresAt: string | null;\n}\ninterface GroupRow {\n id: number;\n name: string;\n isActive: number; // PowerSync stores booleans as 0/1\n}\ninterface GroupAccessKeyRow {\n id: string;\n groupId: number;\n accessKey: string;\n effect: string;\n expiresAt?: string | null;\n}\nexport interface AuthProviderProps {\n children: ReactNode;\n /**\n * Enable entity-level permissions (Project, Client, ProjectDatabase access control).\n * When enabled, wraps children with PermissionProvider.\n * @default false\n */\n enableEntityPermissions?: boolean;\n}\n\n// ============================================================================\n// Permission Helpers\n// ============================================================================\n\n/** Maps permission action strings to numeric levels for comparison */\nfunction getPermissionLevel(action: string): number {\n switch (action.toLowerCase()) {\n case \"view\":\n case \"read\":\n return 1;\n case \"edit\":\n case \"write\":\n return 2;\n case \"admin\":\n case \"delete\":\n case \"share\":\n return 3;\n default:\n return 0;\n }\n}\n\n/** Check if a date string is not expired (null = never expires) */\nfunction isNotExpired(expiresAt: string | null | undefined): boolean {\n return !expiresAt || new Date(expiresAt) > new Date();\n}\n\n/**\n * Check if an access key pattern matches a requested key.\n * Supports wildcards (*) in any segment.\n *\n * Examples:\n * - \"*:*:*\" matches everything (super admin)\n * - \"project:*:read\" matches project:123:read\n * - \"project:123:*\" matches project:123:read, project:123:write\n */\nfunction matchesAccessPattern(pattern: string, requestedKey: string): boolean {\n if (pattern === requestedKey) return true;\n if (pattern === \"*:*:*\") return true;\n const patternParts = pattern.split(\":\");\n const keyParts = requestedKey.split(\":\");\n if (patternParts.length !== keyParts.length) return false;\n for (let i = 0; i < patternParts.length; i++) {\n if (patternParts[i] === \"*\") continue;\n if (patternParts[i] !== keyParts[i]) return false;\n }\n return true;\n}\n\n// ============================================================================\n// AuthProvider Component\n// ============================================================================\n\nexport function AuthProvider({\n children,\n enableEntityPermissions = false\n}: AuthProviderProps) {\n const supabase = useSupabase();\n\n // Auth state\n const [currentUser, setCurrentUser] = useState<User | null | undefined>(undefined);\n const [userNeedsChange, setUserNeedsChange] = useState(true);\n const [onSignOutCallbacks, setOnSignOutCallbacks] = useState(new Map<string, () => any>());\n\n // ─── Auth Actions ─────────────────────────────────────────────────────────\n\n async function registerAsync(register: SignUpWithPasswordCredentials) {\n const response = await supabase.auth.signUp(register);\n if (response.data.user) {\n setCurrentUser(prev => prev?.id === response.data.user?.id ? prev : response.data.user);\n }\n return response;\n }\n async function signInAsync(username: string, password: string) {\n const response_0 = await supabase.auth.signInWithPassword({\n email: username,\n password\n });\n if (response_0.data.user) {\n setCurrentUser(prev_0 => prev_0?.id === response_0.data.user?.id ? prev_0 : response_0.data.user);\n }\n return response_0;\n }\n const signOutAsync = useCallback(async () => {\n const response_1 = await supabase.auth.signOut();\n if (!response_1.error) {\n Array.from(onSignOutCallbacks.values()).forEach(cb => cb());\n }\n return response_1;\n }, [supabase.auth, onSignOutCallbacks]);\n function onSignOut(action: () => any) {\n const id = newUuid();\n setOnSignOutCallbacks(x => new Map(x).set(id, action));\n return id;\n }\n function removeOnSignOut(id_0: string) {\n setOnSignOutCallbacks(x_0 => {\n const map = new Map(x_0);\n map.delete(id_0);\n return map;\n });\n }\n async function refreshAsync() {}\n\n // ─── Session Management with Timeout ──────────────────────────────────────\n\n useEffect(() => {\n const {\n data: {\n subscription\n }\n } = supabase.auth.onAuthStateChange(event => {\n if (event === \"SIGNED_IN\" || event === \"SIGNED_OUT\") {\n setUserNeedsChange(true);\n }\n });\n return () => subscription.unsubscribe();\n }, [supabase.auth]);\n useEffect(() => {\n if (!userNeedsChange) return;\n let cancelled = false;\n async function fetchSessionWithTimeout() {\n try {\n // Race session fetch against timeout to prevent indefinite hangs\n const timeoutPromise = new Promise<never>((_, reject) => {\n setTimeout(() => {\n reject(new Error(`Session fetch timed out after ${SESSION_FETCH_TIMEOUT_MS}ms`));\n }, SESSION_FETCH_TIMEOUT_MS);\n });\n const result = await Promise.race([supabase.auth.getSession(), timeoutPromise]);\n if (cancelled) return;\n const newUser = result?.data?.session?.user ?? null;\n setCurrentUser(prev_2 => {\n if (newUser === null) return null;\n if (prev_2?.id === newUser?.id) return prev_2;\n return newUser;\n });\n setUserNeedsChange(false);\n } catch (error) {\n if (cancelled) return;\n console.error(\"Failed to get session (timeout or error):\", error);\n setCurrentUser(prev_1 => prev_1 === null ? prev_1 : null);\n setUserNeedsChange(false);\n }\n }\n fetchSessionWithTimeout();\n return () => {\n cancelled = true;\n };\n }, [userNeedsChange, supabase.auth]);\n\n // ─── Query Profile and Access via useDbQuery ──────────────────────────────\n // Uses auto strategy: Supabase primary, PowerSync offline backup\n\n const isUserReady = isUsable(currentUser);\n\n // All queries use realtime: true for automatic updates (no manual channel subscriptions)\n const {\n data: profileData,\n isLoading: profileLoading\n } = useDbQuery<ProfileRow>(\"core.Profile\", {\n where: {\n id: currentUser?.id\n },\n enabled: isUserReady,\n realtime: true\n });\n const {\n data: directAccess,\n isLoading: directAccessLoading\n } = useDbQuery<UserAccessRow>(\"core.UserAccess\", {\n where: {\n userId: currentUser?.id\n },\n enabled: isUserReady,\n realtime: true\n });\n const {\n data: userGroups,\n isLoading: userGroupsLoading\n } = useDbQuery<UserGroupRow>(\"core.UserGroup\", {\n where: {\n userId: currentUser?.id\n },\n enabled: isUserReady,\n realtime: true\n });\n const {\n data: groups,\n isLoading: groupsLoading\n } = useDbQuery<GroupRow>(\"core.Group\", {\n where: {\n isActive: 1\n },\n enabled: isUserReady,\n realtime: true\n });\n\n // Get group IDs user belongs to\n const groupIds = useMemo(() => userGroups?.map(ug => ug.groupId) ?? [], [userGroups]);\n\n // Map groups by ID for O(1) lookups\n const groupsMap = useMemo(() => new Map(groups?.map(g => [g.id, g]) ?? []), [groups]);\n const {\n data: groupAccess,\n isLoading: groupAccessLoading\n } = useDbQuery<GroupAccessKeyRow>(\"core.GroupAccessKey\", {\n where: groupIds.length > 0 ? {\n groupId: {\n in: groupIds\n }\n } : undefined,\n enabled: groupIds.length > 0,\n realtime: true\n });\n\n // ─── Derived Data ─────────────────────────────────────────────────────────\n\n const profile = profileData?.[0] ?? null;\n\n // Track previous profile status for signout logic\n const prevProfileStatusRef = useRef<string | null | undefined>(undefined);\n\n // Auto-signout if profile becomes archived/suspended\n useEffect(() => {\n const currentStatus = profile?.status;\n const prevStatus = prevProfileStatusRef.current;\n\n // Only trigger signout if status changed FROM active TO archived/suspended\n if (prevStatus === \"active\" && (currentStatus === \"archived\" || currentStatus === \"suspended\")) {\n signOutAsync();\n }\n prevProfileStatusRef.current = currentStatus;\n }, [profile?.status, signOutAsync]);\n\n // All access keys with metadata\n const allAccessKeys = useMemo(() => {\n const keys: Array<{\n accessKey: string;\n effect: string;\n source: \"direct\" | \"group\";\n expiresAt?: string | null;\n }> = [];\n\n // Add direct access keys (filter out expired)\n directAccess?.forEach(a => {\n if (isNotExpired(a.expiresAt)) {\n keys.push({\n accessKey: a.accessKey,\n effect: a.effect ?? \"allow\",\n source: \"direct\",\n expiresAt: a.expiresAt\n });\n }\n });\n\n // Add group access keys (only from active groups user belongs to)\n const activeGroupIds = new Set(userGroups?.filter(ug_0 => {\n const group = groupsMap.get(ug_0.groupId);\n return group?.isActive === 1 && isNotExpired(ug_0.expiresAt);\n }).map(ug_1 => ug_1.groupId) ?? []);\n groupAccess?.forEach(ga => {\n if (activeGroupIds.has(ga.groupId) && isNotExpired(ga.expiresAt)) {\n keys.push({\n accessKey: ga.accessKey,\n effect: ga.effect ?? \"allow\",\n source: \"group\",\n expiresAt: ga.expiresAt\n });\n }\n });\n return keys;\n }, [directAccess, userGroups, groupsMap, groupAccess]);\n\n // Combine access keys into a simple string array for hasAccess checks\n const combinedAccess: string[] = useMemo(() => {\n const uniqueKeys = new Set<string>();\n for (const item of allAccessKeys) {\n if (item.accessKey && item.effect === \"allow\") {\n uniqueKeys.add(item.accessKey);\n }\n }\n return Array.from(uniqueKeys);\n }, [allAccessKeys]);\n\n // Compute effective permissions\n const effectivePermissions: EffectivePermission[] = useMemo(() => {\n const permissions: EffectivePermission[] = [];\n for (const item_0 of allAccessKeys) {\n if (item_0.effect !== \"allow\") continue;\n const parts = item_0.accessKey.split(\":\");\n if (parts.length === 3) {\n const [resourceType, resourceId, permission] = parts;\n permissions.push({\n resourceType,\n resourceId,\n permission,\n permissionLevel: getPermissionLevel(permission),\n source: item_0.source,\n inheritedFrom: null,\n expiresAt: item_0.expiresAt ?? null\n });\n }\n }\n return permissions;\n }, [allAccessKeys]);\n\n // Profile status values\n const profileStatus = profile?.status as ProfileStatus | undefined;\n const isArchived = profileStatus === \"archived\";\n const isSuspended = profileStatus === \"suspended\";\n\n // ─── hasAccess Function ───────────────────────────────────────────────────\n\n const hasAccess = useCallback((key: string) => {\n // Archived/suspended users have no access\n if (isArchived || isSuspended) return false;\n if (!isUsable(combinedAccess)) return false;\n\n // Super-admin key bypasses all permission checks\n if (combinedAccess.includes(\"*:*:*\")) return true;\n\n // Check exact match\n if (combinedAccess.includes(key)) return true;\n\n // Empty key = no restriction\n if (!isUsable(key)) return true;\n\n // Check wildcard patterns\n for (const pattern of combinedAccess) {\n if (matchesAccessPattern(pattern, key)) return true;\n }\n\n // Check permission levels for type:id:action format\n const parts_0 = key.split(\":\");\n if (parts_0.length === 3) {\n const [type, id_1, action_0] = parts_0;\n const requiredLevel = getPermissionLevel(action_0);\n const hasPermission = effectivePermissions.some(p => p.resourceType === type && p.resourceId === id_1 && p.permissionLevel >= requiredLevel);\n if (hasPermission) return true;\n }\n return false;\n }, [combinedAccess, effectivePermissions, isArchived, isSuspended]);\n\n // ─── Loading State ────────────────────────────────────────────────────────\n\n const isAccessLoading = directAccessLoading || userGroupsLoading || groupsLoading || groupAccessLoading;\n const authState = useMemo(() => ({\n hasAccess,\n user: currentUser,\n profile,\n access: combinedAccess,\n effectivePermissions,\n profileStatus,\n isArchived,\n isSuspended,\n isLoading: currentUser === null ? false : profileLoading || isAccessLoading || currentUser === undefined,\n signInAsync,\n signOutAsync,\n onSignOut,\n removeOnSignOut,\n registerAsync,\n refreshAsync\n }), [hasAccess, currentUser, profile, combinedAccess, effectivePermissions, profileStatus, isArchived, isSuspended, profileLoading, isAccessLoading]);\n\n // ─── Render ───────────────────────────────────────────────────────────────\n\n const content = enableEntityPermissions ? <PermissionProvider>{children}</PermissionProvider> : children;\n return <setupAuthContext.Provider value={authState}>\n {content}\n </setupAuthContext.Provider>;\n}\nexport type Profile = ProfileRow;","import { c as _c } from \"react/compiler-runtime\";\nimport { ReactNode, createContext, useContext, useEffect, useMemo, useState, useCallback, useRef } from \"react\";\nimport { useDbQuery as useQuery } from \"../../useDbQuery\";\nimport { useDbUpsert as useUpsert } from \"../../useDbUpsert\";\nimport useSupabase, { Database } from \"../../useSupabase\";\nimport { isUsable } from \"@pol-studios/utils\";\nimport { setupAuthContext } from \"./AuthProvider\";\n\n// UserMetadata query constant\nconst UserMetadataQuery = {\n schema: \"core\",\n table: \"UserMetadata\",\n defaultQuery: \"key, userId, value\"\n} as const;\n\n// Type definitions for UserMetadata\nexport type UserMetadataRow = Database[\"core\"][\"Tables\"][\"UserMetadata\"][\"Row\"];\nexport type UserMetadataInsert = Database[\"core\"][\"Tables\"][\"UserMetadata\"][\"Insert\"];\nexport type UserMetadataUpdate = Database[\"core\"][\"Tables\"][\"UserMetadata\"][\"Update\"];\n\n// Context interface\nexport interface UserMetadataContextType {\n metadata: Record<string, string>;\n isLoading: boolean;\n error: Error | null;\n setMetadata: (key: string, value: string) => Promise<void>;\n getMetadata: (key: string) => string | undefined;\n removeMetadata: (key: string) => Promise<void>;\n refreshMetadata: () => Promise<void>;\n}\n\n// Create context\nexport const userMetadataContext = createContext<UserMetadataContextType | null>(null);\n\n// Provider component\nexport function UserMetadataProvider({\n children\n}: {\n children: ReactNode;\n}) {\n const supabase = useSupabase();\n const [metadata, setMetadataState] = useState<Record<string, string>>({});\n const [isLoading, setIsLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n // Get current user ID from auth context\n const setupAuth = useContext(setupAuthContext);\n const userId = setupAuth?.user?.id;\n\n // Query to fetch all user metadata\n const metadataQuery = useQuery(supabase.schema(\"core\").from(\"UserMetadata\").select(UserMetadataQuery.defaultQuery).eq(\"userId\", userId!).order(\"key\"), {\n enabled: isUsable(userId),\n crossOrganization: true\n });\n\n // Upsert mutation for updating metadata\n const upsertMutation = useUpsert({\n table: \"UserMetadata\",\n schema: \"core\"\n }, [\"userId\", \"key\"] // composite primary keys\n );\n\n // Ref to hold mutation to avoid infinite loops in useCallback dependencies\n const upsertMutationRef = useRef(upsertMutation);\n upsertMutationRef.current = upsertMutation;\n\n // Update local state when query data changes\n useEffect(() => {\n if (metadataQuery.data && Array.isArray(metadataQuery.data)) {\n const metadataMap: Record<string, string> = {};\n metadataQuery.data.forEach((item: any) => {\n metadataMap[item.key] = item.value;\n });\n setMetadataState(metadataMap);\n setIsLoading(false);\n setError(null);\n } else if (metadataQuery.error) {\n setError(metadataQuery.error);\n setIsLoading(false);\n } else if (metadataQuery.isLoading) {\n setIsLoading(true);\n } else if (metadataQuery.data && !Array.isArray(metadataQuery.data)) {\n // Handle case where data is not an array (e.g., empty response or count)\n setMetadataState({});\n setIsLoading(false);\n }\n }, [metadataQuery.data, metadataQuery.error, metadataQuery.isLoading]);\n\n // Set metadata function\n const setMetadata = useCallback(async (key: string, value: string) => {\n if (!userId) {\n throw new Error(\"User not authenticated\");\n }\n try {\n await upsertMutationRef.current.mutateAsync({\n userId,\n key,\n value\n });\n\n // Update local state optimistically\n setMetadataState(prev => ({\n ...prev,\n [key]: value\n }));\n } catch (err) {\n setError(err as Error);\n throw err;\n }\n }, [userId]);\n\n // Get metadata function\n const getMetadata = useCallback((key_0: string): string | undefined => {\n return metadata[key_0];\n }, [metadata]);\n\n // Remove metadata function\n const removeMetadata = useCallback(async (key_1: string) => {\n if (!userId) {\n throw new Error(\"User not authenticated\");\n }\n try {\n await supabase.schema(\"core\").from(\"UserMetadata\").delete().eq(\"userId\", userId).eq(\"key\", key_1);\n\n // Update local state\n setMetadataState(prev_0 => {\n const newState = {\n ...prev_0\n };\n delete newState[key_1];\n return newState;\n });\n } catch (err_0) {\n setError(err_0 as Error);\n throw err_0;\n }\n }, [userId, supabase]);\n\n // Refresh metadata function\n const refreshMetadata = useCallback(async () => {\n await metadataQuery.refetch();\n }, [metadataQuery]);\n\n // Context value\n const contextValue = useMemo(() => ({\n metadata,\n isLoading,\n error,\n setMetadata,\n getMetadata,\n removeMetadata,\n refreshMetadata\n }), [metadata, isLoading, error, setMetadata, getMetadata, removeMetadata, refreshMetadata]);\n return <userMetadataContext.Provider value={contextValue}>\n {children}\n </userMetadataContext.Provider>;\n}\n\n// Hook to use the context\nexport function useUserMetadata() {\n const context = useContext(userMetadataContext);\n if (!context) {\n throw new Error(\"useUserMetadata must be used within a UserMetadataProvider\");\n }\n return context;\n}\n\n// Convenience hook for getting a specific metadata value\nexport function useUserMetadataValue(key) {\n const $ = _c(3);\n const {\n getMetadata\n } = useUserMetadata();\n let t0;\n if ($[0] !== getMetadata || $[1] !== key) {\n t0 = getMetadata(key);\n $[0] = getMetadata;\n $[1] = key;\n $[2] = t0;\n } else {\n t0 = $[2];\n }\n return t0;\n}\n\n// Convenience hook for setting a specific metadata value\nexport function useSetUserMetadata() {\n const $ = _c(3);\n const {\n setMetadata,\n removeMetadata\n } = useUserMetadata();\n let t0;\n if ($[0] !== removeMetadata || $[1] !== setMetadata) {\n t0 = {\n setMetadata,\n removeMetadata\n };\n $[0] = removeMetadata;\n $[1] = setMetadata;\n $[2] = t0;\n } else {\n t0 = $[2];\n }\n return t0;\n}\n\n// Advanced state-like hook with JSON serialization support\nexport function useUserMetadataState(key, defaultValue, options) {\n const $ = _c(11);\n const {\n metadata,\n setMetadata,\n isLoading\n } = useUserMetadata();\n const serialize = options?.serialize ?? _temp;\n const deserialize = options?.deserialize ?? _temp2;\n let t0;\n bb0: {\n const rawValue = metadata[key];\n if (!rawValue) {\n t0 = defaultValue;\n break bb0;\n }\n ;\n try {\n let t2;\n if ($[0] !== deserialize || $[1] !== rawValue) {\n t2 = deserialize(rawValue);\n $[0] = deserialize;\n $[1] = rawValue;\n $[2] = t2;\n } else {\n t2 = $[2];\n }\n t0 = t2;\n } catch (t1) {\n const error = t1;\n console.warn(`Failed to deserialize metadata for key \"${key}\":`, error);\n t0 = defaultValue;\n }\n }\n const currentValue = t0;\n let t1;\n if ($[3] !== key || $[4] !== serialize || $[5] !== setMetadata) {\n t1 = async value_1 => {\n const serializedValue = serialize(value_1);\n await setMetadata(key, serializedValue);\n };\n $[3] = key;\n $[4] = serialize;\n $[5] = setMetadata;\n $[6] = t1;\n } else {\n t1 = $[6];\n }\n const setValue = t1;\n let t2;\n if ($[7] !== currentValue || $[8] !== isLoading || $[9] !== setValue) {\n t2 = [currentValue, setValue, isLoading];\n $[7] = currentValue;\n $[8] = isLoading;\n $[9] = setValue;\n $[10] = t2;\n } else {\n t2 = $[10];\n }\n return t2;\n}\nfunction _temp2(value_0) {\n return JSON.parse(value_0);\n}\nfunction _temp(value) {\n return JSON.stringify(value);\n}","import { c as _c } from \"react/compiler-runtime\";\nimport { useMutation } from \"@tanstack/react-query\";\nimport useSupabase, { Database } from \"./useSupabase\";\nimport { useQueriesForTableLoader, useUpdateMutation, useUpsertItem } from \"@supabase-cache-helpers/postgrest-react-query\";\nimport { GetResult } from \"./parser/select-query-parser\";\nimport { GenericSchema } from \"./parser/types\";\nimport { isUsable } from \"@pol-studios/utils\";\nimport { omit } from \"@pol-studios/utils\";\nimport { buildNormalizedQuery } from \"@supabase-cache-helpers/postgrest-core\";\ntype ItemType<T> = T extends Array<infer U> ? U : T;\nexport type MutationOption = Parameters<typeof useUpdateMutation>[3];\nexport type useDbUpsertResponse = ReturnType<typeof useDbUpsert>;\nexport function useDbUpsert(relation, t0, query, mutationOption) {\n const $ = _c(16);\n let t1;\n if ($[0] !== t0) {\n t1 = t0 === undefined ? [\"id\"] : t0;\n $[0] = t0;\n $[1] = t1;\n } else {\n t1 = $[1];\n }\n const primaryKeys = t1;\n const tableName = typeof relation === \"object\" ? relation.table : relation;\n const schemaName = typeof relation === \"object\" ? String(relation.schema) : \"public\";\n const supabase = useSupabase();\n let t2;\n if ($[2] !== primaryKeys) {\n t2 = primaryKeys.map(_temp);\n $[2] = primaryKeys;\n $[3] = t2;\n } else {\n t2 = $[3];\n }\n const primaryKeysAsStrings = t2 as string[];\n const t3 = primaryKeysAsStrings as any;\n const t4 = relation as any;\n let t5;\n if ($[4] !== t3 || $[5] !== t4) {\n t5 = {\n primaryKeys: t3,\n table: t4,\n schema: \"public\"\n };\n $[4] = t3;\n $[5] = t4;\n $[6] = t5;\n } else {\n t5 = $[6];\n }\n const upsertItem = useUpsertItem(t5);\n const queriesForTable = useQueriesForTableLoader(tableName);\n let t6;\n if ($[7] !== primaryKeys || $[8] !== primaryKeysAsStrings || $[9] !== queriesForTable || $[10] !== query || $[11] !== schemaName || $[12] !== supabase || $[13] !== tableName || $[14] !== upsertItem) {\n t6 = {\n mutationFn: async item => {\n let result = null;\n const selectQuery = buildNormalizedQuery({\n queriesForTable,\n query\n });\n const insert = async function insert() {\n const keysToFilter = primaryKeys.filter(x => isUsable((item as any)[x]) === false);\n const keysToFilterAsStrings = keysToFilter.map(_temp2) as string[];\n const response = await (supabase as any).schema(schemaName as \"public\" | \"core\").from(tableName).insert(omit(item as any, keysToFilterAsStrings as any) as any).select(query).single();\n if (response.error) {\n throw response.error;\n }\n result = response.data as any;\n if (result) {\n upsertItem(result as any);\n }\n };\n const isUpsertable = primaryKeys.every(x_0 => x_0 in item && isUsable((item as any)[x_0]));\n if (isUpsertable) {\n const query_0 = (supabase as any).schema(schemaName as \"public\" | \"core\").from(tableName).update(omit(item as any, primaryKeysAsStrings as any) as any);\n primaryKeys.forEach(x_1 => {\n query_0.eq(String(x_1), (item as any)[x_1]);\n });\n const queryResponse = await query_0.select(selectQuery?.selectQuery).single();\n console.log(\"queryResponse\", queryResponse, tableName);\n if (queryResponse.status === 406) {\n await insert();\n } else {\n if (queryResponse.error) {\n throw queryResponse.error;\n }\n if (queryResponse.data) {\n result = queryResponse.data as any;\n if (result) {\n upsertItem(result as any);\n }\n }\n }\n } else {\n await insert();\n }\n return result as any;\n }\n };\n $[7] = primaryKeys;\n $[8] = primaryKeysAsStrings;\n $[9] = queriesForTable;\n $[10] = query;\n $[11] = schemaName;\n $[12] = supabase;\n $[13] = tableName;\n $[14] = upsertItem;\n $[15] = t6;\n } else {\n t6 = $[15];\n }\n const mutation = useMutation(t6);\n return mutation;\n}\nfunction _temp2(k_0) {\n return String(k_0);\n}\nfunction _temp(k) {\n return String(k);\n}"],"mappings":";;;;;;;;;;;;;;AAAO,IAAM,wBAAwB;AAC9B,IAAM,wBAAwB;AAE9B,SAAS,eAAe,OAA0C;AACvE,MAAI,CAAC,MAAO,QAAO;AACnB,SAAO,MAAM,SAAS,gBAAgB,MAAM,YAAY,yBAAyB,MAAM,QAAQ,YAAY,EAAE,SAAS,WAAW;AACnI;;;ACLA,SAAS,SAAS,cAAc;AAGhC,SAAS,YAAY;AACrB,SAAS,gBAAiC;AAC1C,SAAS,uBAAuB;AAWzB,SAASA,YAAmB,OAEhC,QAA+G;AAEhH,QAAM,WAAW,OAAO,OAAO,KAAK;AACpC,QAAM,iBAAiB,SAAS,KAAK,GAAG;AACxC,QAAM,qBAA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AM,aAAa,EAAE,CAAC,MAAM,aAAa;AAC9D,SAAK,OAAM,YAAW;AACpB,YAAM,kBAAkB,UAAU,OAAO;AACzC,YAAM,YAAY,KAAK,eAAe;AAAA,IACxC;AACA,MAAE,CAAC,IAAI;AACP,MAAE,CAAC,IAAI;AACP,MAAE,CAAC,IAAI;AACP,MAAE,CAAC,IAAI;AAAA,EACT,OAAO;AACL,SAAK,EAAE,CAAC;AAAA,EACV;AACA,QAAM,WAAW;AACjB,MAAI;AACJ,MAAI,EAAE,CAAC,MAAM,gBAAgB,EAAE,CAAC,MAAM,aAAa,EAAE,CAAC,MAAM,UAAU;AACpE,SAAK,CAAC,cAAc,UAAU,SAAS;AACvC,MAAE,CAAC,IAAI;AACP,MAAE,CAAC,IAAI;AACP,MAAE,CAAC,IAAI;AACP,MAAE,EAAE,IAAI;AAAA,EACV,OAAO;AACL,SAAK,EAAE,EAAE;AAAA,EACX;AACA,SAAO;AACT;AACA,SAASF,QAAO,SAAS;AACvB,SAAO,KAAK,MAAM,OAAO;AAC3B;AACA,SAASD,OAAM,OAAO;AACpB,SAAO,KAAK,UAAU,KAAK;AAC7B;","names":["useDbQuery","createContext","useMemo","useRef","createContext","useRef","useMemo","useCallback","useEffect","useMemo","useRef","useState","jsx","useState","useCallback","useEffect","useMemo","useRef","_c","createContext","useContext","useEffect","useMemo","useState","useCallback","useRef","isUsable","omit","insert","isUsable","omit","isUsable","jsx","createContext","useState","useContext","useDbQuery","isUsable","useRef","useEffect","useCallback","useMemo","_c","_temp","_temp2","t2","t1"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/useDbQueryById.ts","../src/hooks/useAdvanceQuery.ts","../src/hooks/useDbInsert.ts","../src/hooks/useDbUpdate.ts","../src/hooks/useDbUpsert.ts","../src/hooks/useDbDelete.ts","../src/hooks/useDbInfiniteQuery.ts","../src/hooks/useDbCount.ts","../src/hooks/useSyncStatus.ts","../src/hooks/useSyncControl.ts","../src/hooks/useOnlineStatus.ts"],"sourcesContent":["/**\n * V3 useDbQueryById Hook\n *\n * React hook for querying a single record by ID from a table.\n * Works identically whether PowerSync or Supabase is the backend.\n * Uses React Query for state management and caching.\n */\n\nimport { useCallback, useEffect, useMemo } from \"react\";\nimport { useQuery } from \"@tanstack/react-query\";\nimport { useDataLayerCore } from \"./useDataLayer\";\nimport type { WhereClause } from \"../core/types\";\nimport { devLog, devWarn } from \"../utils/dev-log\";\n\n// =============================================================================\n// Types\n// =============================================================================\n\n/**\n * Options for useDbQueryById hook\n */\nexport interface UseDbQueryByIdOptions {\n /** Columns to select (Supabase-style select string) */\n select?: string;\n /** Whether the query is enabled (default: true if id is provided) */\n enabled?: boolean;\n /** React Query stale time in ms (default: 30000) */\n staleTime?: number;\n}\n\n/**\n * Result from useDbQueryById hook\n */\nexport interface UseDbQueryByIdResult<T> {\n /** Query data (undefined while loading, null if not found) */\n data: T | null | undefined;\n /** Whether query is loading (initial load) */\n isLoading: boolean;\n /** Whether query is in pending state */\n isPending: boolean;\n /** Whether query is currently fetching (including refetch) */\n isFetching: boolean;\n /** Query error if any */\n error: Error | null;\n /** Refetch the query */\n refetch: () => Promise<void>;\n}\n\n// =============================================================================\n// Helper Functions\n// =============================================================================\n\n/**\n * Build a query key for React Query\n *\n * Creates a stable, unique key for caching based on table, ID, and select.\n * Keys are namespaced with \"v3\" to avoid collisions with V2 queries.\n */\nfunction buildQueryKey(table: string, id: string | number | null | undefined, select?: string): unknown[] {\n return [\"v3\", \"queryById\", table, id, select ?? \"*\"];\n}\n\n// =============================================================================\n// Hook Implementation\n// =============================================================================\n\n/**\n * Hook for querying a single record by ID\n *\n * This hook provides a unified interface for fetching a single record that works\n * identically whether the backend is PowerSync (offline-first) or\n * Supabase (online-only). It uses React Query for caching and state management.\n *\n * Features:\n * - Automatic backend selection based on DataLayerProvider configuration\n * - React Query integration for caching, deduplication, and background updates\n * - Automatic disabling when ID is null/undefined\n * - Fallback to query with where clause if adapter doesn't support queryById\n * - Type-safe with generic type parameter\n *\n * @param table - The table name to query\n * @param id - The record ID (query is disabled if null/undefined)\n * @param options - Query options (select, enabled, staleTime)\n * @returns Query result with data, loading states, error, and refetch function\n *\n * @example\n * // Basic query by ID\n * const { data, isLoading, error } = useDbQueryById<Task>(\"Task\", taskId);\n *\n * @example\n * // Query with relations\n * const { data, isLoading, error } = useDbQueryById<Task>(\"Task\", taskId, {\n * select: \"*, Project(*), AssignedUser:User(*)\",\n * });\n *\n * @example\n * // Conditional query based on other state\n * const { data } = useDbQueryById<Project>(\"Project\", selectedProjectId, {\n * enabled: hasPermission && !!selectedProjectId,\n * });\n *\n * @example\n * // With custom stale time\n * const { data } = useDbQueryById<User>(\"User\", userId, {\n * staleTime: 60000, // 1 minute\n * });\n */\nexport function useDbQueryById<T = Record<string, unknown>>(table: string, id: string | number | null | undefined, options: UseDbQueryByIdOptions = {}): UseDbQueryByIdResult<T> {\n const {\n registry\n } = useDataLayerCore();\n const {\n select,\n enabled = id != null,\n staleTime = 30000\n } = options;\n\n // Get adapter for this table\n // No isInitialized check needed - if we get here, core context exists = initialized\n const adapter = useMemo(() => {\n try {\n return registry.getAdapter(table);\n } catch {\n return null;\n }\n }, [registry, table]);\n\n // Build query key - memoized to prevent unnecessary re-renders\n const queryKey = useMemo(() => buildQueryKey(table, id, select), [table, id, select]);\n\n // Query function\n const queryFn = useCallback(async (): Promise<T | null> => {\n if (!adapter) {\n throw new Error(`Adapter not available for table: ${table}`);\n }\n if (id == null) {\n return null;\n }\n\n // Use queryById if available, otherwise fall back to query with where\n if (adapter.queryById) {\n return adapter.queryById<T>(table, String(id), {\n select\n });\n }\n\n // Fallback: use query with where clause\n const result = await adapter.query<T>(table, {\n select,\n where: {\n id\n } as WhereClause,\n limit: 1\n });\n return result.data[0] ?? null;\n }, [adapter, table, id, select]);\n\n // Execute query with React Query\n const query = useQuery({\n queryKey,\n queryFn,\n enabled: enabled && adapter !== null && id != null,\n staleTime\n });\n\n // Dev logging for debugging\n useEffect(() => {\n const adapterName = adapter?.name ?? \"unknown\";\n\n // Log errors\n if (query.isError && query.error) {\n devWarn(\"useDbQueryById\", `${table}(${id}) via ${adapterName}: Error - ${query.error.message}`);\n }\n\n // Log not found (only after successful fetch, not during loading)\n if (query.isSuccess && query.data === null) {\n devLog(\"useDbQueryById\", `${table}(${id}) via ${adapterName}: not found`);\n }\n }, [query.isError, query.error, query.isSuccess, query.data, table, id, adapter]);\n\n // Build refetch function\n const refetch = useCallback(async () => {\n await query.refetch();\n }, [query]);\n return {\n data: query.data,\n isLoading: query.isLoading,\n isPending: query.isPending,\n isFetching: query.isFetching,\n error: query.error as Error | null,\n refetch\n };\n}\nexport default useDbQueryById;","/**\n * V3 useAdvanceQuery Hook\n *\n * Hybrid query hook that combines PowerSync (local SQLite) with edge function filtering.\n * - When NO filters active: Uses PowerSync for fast local queries that stay in sync\n * - When filters active: Uses edge function for complex filtering\n *\n * This provides the best of both worlds:\n * - Fast, reactive local queries via PowerSync\n * - Complex filtering, natural language queries, and aggregations via edge function\n *\n * @example\n * const [result, filters, setFilters] = useAdvanceQuery<Equipment[]>(\n * \"EquipmentFixtureUnit\",\n * {\n * select: \"*, EquipmentFixtureUnitControl(*)\",\n * where: { projectDatabaseId: 123 },\n * orderBy: [{ field: \"unitNumber\", direction: \"asc\" }],\n * filterKey: \"equipment-filters\",\n * }\n * );\n */\n\nimport { Dispatch, SetStateAction, useCallback, useMemo, useRef, useState, useEffect } from \"react\";\nimport { useQuery } from \"@tanstack/react-query\";\nimport { useDataLayerCore } from \"./useDataLayer\";\nimport { useDbQuery } from \"./useDbQuery\";\nimport type { TableIdentifier, ResolveRowType, UseDbQueryOptions } from \"./useDbQuery\";\nimport type { QueryOptions } from \"../core/types\";\nimport { useSessionStorageState } from \"@pol-studios/hooks/storage\";\nimport { isUsable, omit } from \"@pol-studios/utils\";\nimport { getSupabaseUrl } from \"../config\";\nimport useSupabase from \"../useSupabase\";\nimport { devLog, devWarn } from \"../utils/dev-log\";\n\n// =============================================================================\n// Types (re-exported from useDbAdvanceQuery for compatibility)\n// =============================================================================\n\nexport type FilterOperator = \"=\" | \">\" | \">=\" | \"<\" | \"<=\" | \"contains\" | \"ilike\" | \"is\" | \"in\" | \"ai_search\";\nexport interface Filter {\n id: string;\n field: string;\n op: FilterOperator;\n value: string | number | string[] | number[] | boolean | null;\n not?: boolean;\n similarity?: number;\n where?: string;\n display?: string;\n}\nexport interface FilterGroup {\n id: string;\n op: \"AND\" | \"OR\";\n filters: Array<Filter | FilterGroup>;\n not?: boolean;\n}\nexport interface Pagination {\n offset?: number;\n limit?: number;\n}\nexport interface Sort {\n field: string;\n direction: \"asc\" | \"desc\";\n}\nexport interface QueryState extends FilterGroup {\n pagination?: Pagination;\n sort?: Sort[];\n distinctOn?: string[];\n naturalLanguageQuery?: string;\n isReady: boolean;\n}\nexport interface ClarificationQuestion {\n question: string;\n suggestions: Array<{\n interpretation: string;\n field_path: string;\n example: string;\n confidence: number;\n }>;\n}\n\n// =============================================================================\n// Options and Result Types\n// =============================================================================\n\nexport interface UseAdvanceQueryOptions extends Omit<UseDbQueryOptions, \"realtime\"> {\n /** Key for persisting filter state (required for filter state persistence) */\n filterKey: string;\n /** Initial filter state */\n initialFilters?: QueryState;\n /** Timeout for edge function requests in ms (default: 15000) */\n timeout?: number;\n /** Count mode: \"exact\" | \"estimated\" | \"\" (default: \"exact\") */\n count?: \"exact\" | \"estimated\" | \"\";\n /**\n * Whether to enable real-time subscriptions\n * - PowerSync path: Uses watch() for reactive updates (default: true when PowerSync)\n * - Edge function path: Uses Supabase realtime to invalidate query on changes\n */\n realtime?: boolean;\n}\nexport interface UseAdvanceQueryResult<T> {\n data: T[] | undefined;\n isLoading: boolean;\n isPending: boolean;\n isFetching: boolean;\n isRefetching: boolean;\n isSuccess: boolean;\n isError: boolean;\n error: Error | null;\n refetch: () => Promise<void>;\n count?: number;\n clarification?: ClarificationQuestion;\n}\n\n// =============================================================================\n// Default Filter State\n// =============================================================================\n\nconst createDefaultFilterState = (): QueryState => ({\n id: \"root\",\n op: \"AND\",\n filters: [],\n pagination: undefined,\n sort: [],\n isReady: true\n});\n\n// =============================================================================\n// Hook Implementation\n// =============================================================================\n\n/**\n * Hybrid advance query hook\n *\n * Uses PowerSync (local SQLite) when no filters are active for fast, reactive queries.\n * Falls back to edge function when filters are active for complex filtering.\n */\nexport function useAdvanceQuery<T extends TableIdentifier>(table: T, options: UseAdvanceQueryOptions): [UseAdvanceQueryResult<ResolveRowType<T>>, QueryState, Dispatch<SetStateAction<QueryState>>];\nexport function useAdvanceQuery<T>(table: string, options: UseAdvanceQueryOptions): [UseAdvanceQueryResult<T>, QueryState, Dispatch<SetStateAction<QueryState>>];\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useAdvanceQuery<T = any>(table: TableIdentifier | string, options: UseAdvanceQueryOptions): [UseAdvanceQueryResult<T>, QueryState, Dispatch<SetStateAction<QueryState>>] {\n const tableName = typeof table === \"string\" ? table : `${(table as {\n schema: string;\n table: string;\n }).schema}.${(table as {\n schema: string;\n table: string;\n }).table}`;\n const {\n registry,\n queryClient,\n powerSync\n } = useDataLayerCore();\n const supabase = useSupabase();\n const {\n filterKey,\n initialFilters,\n enabled = true,\n timeout = 15000,\n count = \"exact\",\n realtime,\n select,\n where,\n orderBy,\n limit,\n offset,\n ...restOptions\n } = options;\n\n // Determine if realtime should be enabled\n // Default: true for PowerSync path, false for edge function path\n const isPowerSync = powerSync !== null;\n const realtimeEnabled = realtime ?? isPowerSync;\n\n // ==========================================================================\n // Filter State Management\n // ==========================================================================\n\n const defaultFilterState = useMemo(() => initialFilters ?? createDefaultFilterState(),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [] // Only compute once\n );\n const [filtersRaw, setFiltersRaw] = useSessionStorageState<QueryState>(filterKey, defaultFilterState);\n const filters = filtersRaw ?? defaultFilterState;\n\n // Type-safe setFilters wrapper\n const setFilters: Dispatch<SetStateAction<QueryState>> = useCallback(action => {\n if (typeof action === \"function\") {\n setFiltersRaw(prev => action(prev ?? defaultFilterState));\n } else {\n setFiltersRaw(action);\n }\n }, [setFiltersRaw, defaultFilterState]);\n\n // ==========================================================================\n // Determine Query Strategy\n // ==========================================================================\n\n const hasAdvancedFilters = useMemo(() => (filters?.filters?.length ?? 0) > 0 || !!filters?.naturalLanguageQuery, [filters?.filters?.length, filters?.naturalLanguageQuery]);\n\n // Use direct DB query (via useDbQuery) when: no advanced filters\n // useDbQuery handles adapter selection (PowerSync vs Supabase) based on sync status\n // This ensures queries use Supabase during initial sync when PowerSync hasn't synced yet\n const usePowerSyncPath = !hasAdvancedFilters;\n\n // ==========================================================================\n // PowerSync Query (no filters path)\n // ==========================================================================\n\n // Convert orderBy from Sort[] to QueryOptions orderBy format\n const powerSyncOrderBy = useMemo(() => {\n if (filters?.sort && filters.sort.length > 0) {\n return filters.sort.map(s => ({\n field: s.field,\n direction: s.direction\n }));\n }\n return orderBy;\n }, [filters?.sort, orderBy]);\n const powerSyncResult = useDbQuery<T>(table as string, {\n select,\n where,\n orderBy: powerSyncOrderBy,\n limit: filters?.pagination?.limit ?? limit,\n offset: filters?.pagination?.offset ?? offset,\n enabled: enabled && usePowerSyncPath && filters?.isReady !== false,\n realtime: realtimeEnabled // Enable watch() subscriptions for reactive updates\n });\n\n // ==========================================================================\n // Edge Function Query (with filters path)\n // ==========================================================================\n\n const [extraData, setExtraData] = useState<{\n count?: number;\n key?: string;\n }>({});\n const edgeFunctionQueryKey = useMemo(() => [\"v3\", \"advance-query\", tableName, select, JSON.stringify(where), JSON.stringify(filters)], [tableName, select, where, filters]);\n const edgeFunctionResult = useQuery<{\n data: T[];\n count?: number;\n clarification?: ClarificationQuestion;\n }>({\n queryKey: edgeFunctionQueryKey,\n queryFn: async ({\n signal\n }) => {\n const {\n data: {\n session\n }\n } = await supabase.auth.getSession();\n if (!session?.access_token) {\n throw new Error(\"No active session\");\n }\n const controller = new AbortController();\n signal.addEventListener(\"abort\", () => controller.abort());\n const timeoutId = setTimeout(() => controller.abort(), timeout);\n try {\n // Build filter body\n const filterBody = {\n id: filters.id || \"root\",\n op: filters.op || \"AND\",\n not: filters.not,\n filters: filters.filters || []\n };\n\n // Parse base where conditions into filters\n const baseFilters: Filter[] = [];\n if (where) {\n Object.entries(where).forEach(([field, value]) => {\n if (value !== undefined && value !== null) {\n if (typeof value === \"object\" && \"in\" in value) {\n // Handle { in: [...] } syntax\n baseFilters.push({\n id: `base-${field}`,\n field,\n op: \"in\",\n value: (value as {\n in: unknown[];\n }).in as string[] | number[]\n });\n } else {\n baseFilters.push({\n id: `base-${field}`,\n field,\n op: \"=\",\n value: value as string | number | boolean | null\n });\n }\n }\n });\n }\n\n // Combine base filters with user filters\n const combinedFilters = [...baseFilters, ...filterBody.filters];\n const currentKey = `${tableName}${select}${JSON.stringify(omit(filters, [\"pagination\", \"isReady\"]))}`;\n const res = await fetch(`${getSupabaseUrl()}/functions/v1/query?forceDenoVersion=2`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${session.access_token}`\n },\n body: JSON.stringify({\n table: tableName,\n schema: \"public\",\n select: select ?? \"*\",\n filters: {\n id: filterBody.id,\n op: filterBody.op,\n not: filterBody.not,\n filters: combinedFilters\n },\n pagination: filters.pagination,\n sort: filters.sort || orderBy?.map(o => ({\n field: o.field,\n direction: o.direction\n })),\n distinctOn: filters.distinctOn,\n naturalLanguageQuery: filters.naturalLanguageQuery,\n count: currentKey === extraData.key ? \"\" : count\n }),\n signal: controller.signal\n });\n if (!res.ok) {\n const errorData = await res.json();\n const errorMessage = typeof errorData?.error === \"string\" ? errorData.error : errorData?.error?.message || errorData?.message || \"Query failed\";\n throw new Error(errorMessage);\n }\n const result = await res.json();\n\n // Handle clarification response\n if (result.clarification) {\n return {\n data: [] as T[],\n count: 0,\n clarification: result.clarification\n };\n }\n setExtraData(prev => ({\n count: prev.key === currentKey ? prev.count : result.count,\n key: currentKey\n }));\n return {\n data: result.data as T[],\n count: result.count\n };\n } finally {\n clearTimeout(timeoutId);\n }\n },\n enabled: enabled && !usePowerSyncPath && filters?.isReady !== false,\n staleTime: 30000,\n gcTime: 300000,\n refetchOnMount: true,\n refetchOnWindowFocus: false\n });\n\n // ==========================================================================\n // Supabase Realtime Subscription (edge function path only)\n // ==========================================================================\n\n // When realtime is enabled and using edge function path,\n // subscribe to Supabase realtime to invalidate query on changes\n useEffect(() => {\n // Only set up realtime for edge function path when realtime is enabled\n if (!realtimeEnabled || usePowerSyncPath || !enabled) {\n return;\n }\n\n // Build filter for the subscription based on where clause\n const channel = supabase.channel(`advance-query-${tableName}-${filterKey}`).on(\"postgres_changes\", {\n event: \"*\",\n // Listen to INSERT, UPDATE, DELETE\n schema: \"public\",\n table: tableName\n // Note: We can't easily filter by complex where clauses,\n // so we invalidate on any change to the table\n }, () => {\n // Invalidate the query to trigger a refetch\n queryClient.invalidateQueries({\n queryKey: edgeFunctionQueryKey\n });\n }).subscribe();\n return () => {\n supabase.removeChannel(channel);\n };\n }, [realtimeEnabled, usePowerSyncPath, enabled, supabase, tableName, filterKey, queryClient, edgeFunctionQueryKey]);\n\n // ==========================================================================\n // Dev Logging (edge function path only - PowerSync path logs via useDbQuery)\n // ==========================================================================\n\n useEffect(() => {\n // Only log for edge function path\n if (usePowerSyncPath) return;\n const pathName = \"EdgeFunction\";\n\n // Log errors\n if (edgeFunctionResult.isError && edgeFunctionResult.error) {\n devWarn(\"useAdvanceQuery\", `${tableName} via ${pathName}: Error - ${edgeFunctionResult.error.message}`);\n }\n\n // Log empty results (only after successful fetch)\n if (edgeFunctionResult.isSuccess && edgeFunctionResult.data?.data?.length === 0) {\n devLog(\"useAdvanceQuery\", `${tableName} via ${pathName}: 0 results`);\n }\n }, [usePowerSyncPath, edgeFunctionResult.isError, edgeFunctionResult.error, edgeFunctionResult.isSuccess, edgeFunctionResult.data, tableName]);\n\n // ==========================================================================\n // Combine Results\n // ==========================================================================\n\n const result = useMemo((): UseAdvanceQueryResult<T> => {\n if (usePowerSyncPath) {\n // PowerSync path\n return {\n data: powerSyncResult.data as T[] | undefined,\n isLoading: powerSyncResult.isLoading,\n isPending: powerSyncResult.isPending,\n isFetching: powerSyncResult.isFetching,\n isRefetching: powerSyncResult.isRefetching,\n isSuccess: powerSyncResult.isSuccess,\n isError: powerSyncResult.isError,\n error: powerSyncResult.error,\n refetch: powerSyncResult.refetch,\n count: powerSyncResult.count ?? powerSyncResult.data?.length\n };\n }\n\n // Edge function path\n return {\n data: edgeFunctionResult.data?.data,\n isLoading: edgeFunctionResult.isLoading,\n isPending: edgeFunctionResult.isPending,\n isFetching: edgeFunctionResult.isFetching,\n isRefetching: edgeFunctionResult.isFetching,\n isSuccess: edgeFunctionResult.isSuccess,\n isError: edgeFunctionResult.isError,\n error: edgeFunctionResult.error as Error | null,\n refetch: async () => {\n await edgeFunctionResult.refetch();\n },\n count: edgeFunctionResult.data?.count ?? extraData.count,\n clarification: edgeFunctionResult.data?.clarification\n };\n }, [usePowerSyncPath, powerSyncResult, edgeFunctionResult, extraData.count]);\n return [result, filters, setFilters];\n}\nexport default useAdvanceQuery;","import { c as _c } from \"react/compiler-runtime\";\n/**\n * V3 useDbInsert Hook\n *\n * React hook for inserting records into a table using the V3 adapter pattern.\n * Integrates with React Query for mutation management and cache invalidation.\n */\n\nimport { useCallback } from \"react\";\nimport { useMutation, useQueryClient } from \"@tanstack/react-query\";\nimport { useDataLayerCore } from \"./useDataLayer\";\n\n/**\n * Options for useDbInsert hook\n */\nexport interface UseDbInsertOptions<T> {\n /** Callback when insert succeeds */\n onSuccess?: (data: T) => void;\n /** Callback when insert fails */\n onError?: (error: Error) => void;\n /** Tables to invalidate after successful insert */\n invalidateTables?: string[];\n}\n\n/**\n * Result from useDbInsert hook\n */\nexport interface UseDbInsertResult<T> {\n /** Trigger insert (fire and forget) */\n mutate: (data: Partial<T>) => void;\n /** Trigger insert and await result */\n mutateAsync: (data: Partial<T>) => Promise<T>;\n /** Whether mutation is in progress */\n isPending: boolean;\n /** Mutation error if any */\n error: Error | null;\n /** Reset mutation state */\n reset: () => void;\n /** Last successful data */\n data: T | undefined;\n}\n\n/**\n * Hook for inserting records into a table\n *\n * Uses the V3 adapter pattern to route inserts to the appropriate backend\n * (PowerSync, Supabase, or Cached) based on table configuration.\n *\n * @param table - The table name to insert into\n * @param options - Optional configuration for callbacks and cache invalidation\n * @returns Mutation result with mutate/mutateAsync functions\n *\n * @example\n * ```typescript\n * const { mutateAsync, isPending } = useDbInsert<Task>(\"Task\");\n * const newTask = await mutateAsync({ title: \"New Task\", status: \"pending\" });\n * ```\n *\n * @example\n * ```typescript\n * // With options\n * const { mutate } = useDbInsert<Project>(\"Project\", {\n * onSuccess: (data) => console.log(\"Created:\", data),\n * onError: (error) => console.error(\"Failed:\", error),\n * invalidateTables: [\"Project\", \"ProjectSummary\"],\n * });\n * ```\n */\nexport function useDbInsert(table, t0) {\n const $ = _c(25);\n let t1;\n if ($[0] !== t0) {\n t1 = t0 === undefined ? {} : t0;\n $[0] = t0;\n $[1] = t1;\n } else {\n t1 = $[1];\n }\n const options = t1;\n const {\n registry\n } = useDataLayerCore();\n const queryClient = useQueryClient();\n const {\n onSuccess,\n onError,\n invalidateTables: t2\n } = options;\n let t3;\n if ($[2] !== t2 || $[3] !== table) {\n t3 = t2 === undefined ? [table] : t2;\n $[2] = t2;\n $[3] = table;\n $[4] = t3;\n } else {\n t3 = $[4];\n }\n const invalidateTables = t3;\n let t4;\n if ($[5] !== registry || $[6] !== table) {\n t4 = async data => {\n const adapter = registry.getAdapter(table, \"write\");\n return await adapter.insert(table, data);\n };\n $[5] = registry;\n $[6] = table;\n $[7] = t4;\n } else {\n t4 = $[7];\n }\n const mutationFn = t4;\n let t5;\n if ($[8] !== invalidateTables || $[9] !== onSuccess || $[10] !== queryClient) {\n t5 = data_0 => {\n invalidateTables.forEach(t => {\n queryClient.invalidateQueries({\n predicate: query => query.queryKey[0] === \"v3\" && query.queryKey[2] === t\n });\n });\n onSuccess?.(data_0);\n };\n $[8] = invalidateTables;\n $[9] = onSuccess;\n $[10] = queryClient;\n $[11] = t5;\n } else {\n t5 = $[11];\n }\n let t6;\n if ($[12] !== onError) {\n t6 = error => {\n onError?.(error instanceof Error ? error : new Error(String(error)));\n };\n $[12] = onError;\n $[13] = t6;\n } else {\n t6 = $[13];\n }\n let t7;\n if ($[14] !== mutationFn || $[15] !== t5 || $[16] !== t6) {\n t7 = {\n mutationFn,\n onSuccess: t5,\n onError: t6\n };\n $[14] = mutationFn;\n $[15] = t5;\n $[16] = t6;\n $[17] = t7;\n } else {\n t7 = $[17];\n }\n const mutation = useMutation(t7);\n const t8 = mutation.error as Error | null;\n let t9;\n if ($[18] !== mutation.data || $[19] !== mutation.isPending || $[20] !== mutation.mutate || $[21] !== mutation.mutateAsync || $[22] !== mutation.reset || $[23] !== t8) {\n t9 = {\n mutate: mutation.mutate,\n mutateAsync: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: t8,\n reset: mutation.reset,\n data: mutation.data\n };\n $[18] = mutation.data;\n $[19] = mutation.isPending;\n $[20] = mutation.mutate;\n $[21] = mutation.mutateAsync;\n $[22] = mutation.reset;\n $[23] = t8;\n $[24] = t9;\n } else {\n t9 = $[24];\n }\n return t9;\n}\nexport default useDbInsert;","import { c as _c } from \"react/compiler-runtime\";\n/**\n * V3 useDbUpdate Hook\n *\n * React hook for updating records in a table using the V3 adapter pattern.\n * Integrates with React Query for mutation management, cache invalidation,\n * and optional optimistic updates.\n */\n\nimport { useCallback } from \"react\";\nimport { useMutation, useQueryClient } from \"@tanstack/react-query\";\nimport { useDataLayerCore } from \"./useDataLayer\";\n\n/**\n * Options for useDbUpdate hook\n */\nexport interface UseDbUpdateOptions<T> {\n /** Callback when update succeeds */\n onSuccess?: (data: T) => void;\n /** Callback when update fails */\n onError?: (error: Error) => void;\n /** Tables to invalidate after successful update */\n invalidateTables?: string[];\n /** Enable optimistic updates */\n optimistic?: boolean;\n}\n\n/**\n * Result from useDbUpdate hook\n */\nexport interface UseDbUpdateResult<T> {\n /** Trigger update (fire and forget) */\n mutate: (params: {\n id: string;\n data: Partial<T>;\n }) => void;\n /** Trigger update and await result */\n mutateAsync: (params: {\n id: string;\n data: Partial<T>;\n }) => Promise<T>;\n /** Whether mutation is in progress */\n isPending: boolean;\n /** Mutation error if any */\n error: Error | null;\n /** Reset mutation state */\n reset: () => void;\n /** Last successful data */\n data: T | undefined;\n}\n\n/**\n * Hook for updating records in a table\n *\n * Uses the V3 adapter pattern to route updates to the appropriate backend\n * (PowerSync, Supabase, or Cached) based on table configuration.\n *\n * @param table - The table name to update records in\n * @param options - Optional configuration for callbacks, cache invalidation, and optimistic updates\n * @returns Mutation result with mutate/mutateAsync functions\n *\n * @example\n * ```typescript\n * const { mutateAsync, isPending } = useDbUpdate<Task>(\"Task\");\n * const updated = await mutateAsync({ id: taskId, data: { status: \"completed\" } });\n * ```\n *\n * @example\n * ```typescript\n * // With optimistic updates\n * const { mutate } = useDbUpdate<Project>(\"Project\", {\n * optimistic: true,\n * onSuccess: (data) => console.log(\"Updated:\", data),\n * onError: (error) => console.error(\"Failed:\", error),\n * });\n * ```\n */\nexport function useDbUpdate(table, t0) {\n const $ = _c(32);\n let t1;\n if ($[0] !== t0) {\n t1 = t0 === undefined ? {} : t0;\n $[0] = t0;\n $[1] = t1;\n } else {\n t1 = $[1];\n }\n const options = t1;\n const {\n registry\n } = useDataLayerCore();\n const queryClient = useQueryClient();\n const {\n onSuccess,\n onError,\n invalidateTables: t2,\n optimistic: t3\n } = options;\n let t4;\n if ($[2] !== t2 || $[3] !== table) {\n t4 = t2 === undefined ? [table] : t2;\n $[2] = t2;\n $[3] = table;\n $[4] = t4;\n } else {\n t4 = $[4];\n }\n const invalidateTables = t4;\n const optimistic = t3 === undefined ? false : t3;\n let t5;\n if ($[5] !== registry || $[6] !== table) {\n t5 = async params => {\n const adapter = registry.getAdapter(table, \"write\");\n return await adapter.update(table, params.id, params.data);\n };\n $[5] = registry;\n $[6] = table;\n $[7] = t5;\n } else {\n t5 = $[7];\n }\n const mutationFn = t5;\n let t6;\n if ($[8] !== optimistic || $[9] !== queryClient || $[10] !== table) {\n t6 = optimistic ? async () => {\n await queryClient.cancelQueries({\n predicate: query => query.queryKey[0] === \"v3\" && query.queryKey[2] === table\n });\n const previousData = queryClient.getQueriesData({\n predicate: query_0 => query_0.queryKey[0] === \"v3\" && query_0.queryKey[2] === table\n });\n return {\n previousData\n };\n } : undefined;\n $[8] = optimistic;\n $[9] = queryClient;\n $[10] = table;\n $[11] = t6;\n } else {\n t6 = $[11];\n }\n let t7;\n if ($[12] !== invalidateTables || $[13] !== onSuccess || $[14] !== queryClient) {\n t7 = data => {\n invalidateTables.forEach(t => {\n queryClient.invalidateQueries({\n predicate: query_1 => query_1.queryKey[0] === \"v3\" && query_1.queryKey[2] === t\n });\n });\n onSuccess?.(data);\n };\n $[12] = invalidateTables;\n $[13] = onSuccess;\n $[14] = queryClient;\n $[15] = t7;\n } else {\n t7 = $[15];\n }\n let t8;\n if ($[16] !== onError || $[17] !== optimistic || $[18] !== queryClient) {\n t8 = (error, _variables, context) => {\n if (optimistic && context?.previousData) {\n context.previousData.forEach(t9 => {\n const [queryKey, data_0] = t9;\n queryClient.setQueryData(queryKey, data_0);\n });\n }\n onError?.(error instanceof Error ? error : new Error(String(error)));\n };\n $[16] = onError;\n $[17] = optimistic;\n $[18] = queryClient;\n $[19] = t8;\n } else {\n t8 = $[19];\n }\n let t9;\n if ($[20] !== mutationFn || $[21] !== t6 || $[22] !== t7 || $[23] !== t8) {\n t9 = {\n mutationFn,\n onMutate: t6,\n onSuccess: t7,\n onError: t8\n };\n $[20] = mutationFn;\n $[21] = t6;\n $[22] = t7;\n $[23] = t8;\n $[24] = t9;\n } else {\n t9 = $[24];\n }\n const mutation = useMutation(t9);\n const t10 = mutation.error as Error | null;\n let t11;\n if ($[25] !== mutation.data || $[26] !== mutation.isPending || $[27] !== mutation.mutate || $[28] !== mutation.mutateAsync || $[29] !== mutation.reset || $[30] !== t10) {\n t11 = {\n mutate: mutation.mutate,\n mutateAsync: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: t10,\n reset: mutation.reset,\n data: mutation.data\n };\n $[25] = mutation.data;\n $[26] = mutation.isPending;\n $[27] = mutation.mutate;\n $[28] = mutation.mutateAsync;\n $[29] = mutation.reset;\n $[30] = t10;\n $[31] = t11;\n } else {\n t11 = $[31];\n }\n return t11;\n}\nexport default useDbUpdate;","import { c as _c } from \"react/compiler-runtime\";\n/**\n * V3 useDbUpsert Hook\n *\n * React hook for upserting (insert or update) records in a table using the V3 adapter pattern.\n * Integrates with React Query for mutation management and cache invalidation.\n */\n\nimport { useCallback } from \"react\";\nimport { useMutation, useQueryClient } from \"@tanstack/react-query\";\nimport { useDataLayerCore } from \"./useDataLayer\";\n\n/**\n * Options for useDbUpsert hook\n */\nexport interface UseDbUpsertOptions<T> {\n /** Callback when upsert succeeds */\n onSuccess?: (data: T) => void;\n /** Callback when upsert fails */\n onError?: (error: Error) => void;\n /** Tables to invalidate after successful upsert */\n invalidateTables?: string[];\n}\n\n/**\n * Result from useDbUpsert hook\n */\nexport interface UseDbUpsertResult<T> {\n /** Trigger upsert (fire and forget) */\n mutate: (data: Partial<T>) => void;\n /** Trigger upsert and await result */\n mutateAsync: (data: Partial<T>) => Promise<T>;\n /** Whether mutation is in progress */\n isPending: boolean;\n /** Mutation error if any */\n error: Error | null;\n /** Reset mutation state */\n reset: () => void;\n /** Last successful data */\n data: T | undefined;\n}\n\n/**\n * Hook for upserting (insert or update) records in a table\n *\n * Uses the V3 adapter pattern to route upserts to the appropriate backend\n * (PowerSync, Supabase, or Cached) based on table configuration.\n *\n * If the record has an ID and exists, it will be updated.\n * Otherwise, a new record will be inserted.\n *\n * @param table - The table name to upsert into\n * @param options - Optional configuration for callbacks and cache invalidation\n * @returns Mutation result with mutate/mutateAsync functions\n *\n * @example\n * ```typescript\n * const { mutateAsync, isPending } = useDbUpsert<Task>(\"Task\");\n * const task = await mutateAsync({ id: existingId, title: \"Updated Title\" });\n * ```\n *\n * @example\n * ```typescript\n * // Insert if no ID, update if ID exists\n * const { mutate } = useDbUpsert<Setting>(\"Setting\", {\n * onSuccess: (data) => console.log(\"Upserted:\", data),\n * invalidateTables: [\"Setting\", \"UserPreferences\"],\n * });\n *\n * // This will insert (no id)\n * mutate({ key: \"theme\", value: \"dark\" });\n *\n * // This will update (has id)\n * mutate({ id: \"setting-123\", key: \"theme\", value: \"light\" });\n * ```\n */\nexport function useDbUpsert(table, t0) {\n const $ = _c(25);\n let t1;\n if ($[0] !== t0) {\n t1 = t0 === undefined ? {} : t0;\n $[0] = t0;\n $[1] = t1;\n } else {\n t1 = $[1];\n }\n const options = t1;\n const {\n registry\n } = useDataLayerCore();\n const queryClient = useQueryClient();\n const {\n onSuccess,\n onError,\n invalidateTables: t2\n } = options;\n let t3;\n if ($[2] !== t2 || $[3] !== table) {\n t3 = t2 === undefined ? [table] : t2;\n $[2] = t2;\n $[3] = table;\n $[4] = t3;\n } else {\n t3 = $[4];\n }\n const invalidateTables = t3;\n let t4;\n if ($[5] !== registry || $[6] !== table) {\n t4 = async data => {\n const adapter = registry.getAdapter(table, \"write\");\n return await adapter.upsert(table, data);\n };\n $[5] = registry;\n $[6] = table;\n $[7] = t4;\n } else {\n t4 = $[7];\n }\n const mutationFn = t4;\n let t5;\n if ($[8] !== invalidateTables || $[9] !== onSuccess || $[10] !== queryClient) {\n t5 = data_0 => {\n invalidateTables.forEach(t => {\n queryClient.invalidateQueries({\n predicate: query => query.queryKey[0] === \"v3\" && query.queryKey[2] === t\n });\n });\n onSuccess?.(data_0);\n };\n $[8] = invalidateTables;\n $[9] = onSuccess;\n $[10] = queryClient;\n $[11] = t5;\n } else {\n t5 = $[11];\n }\n let t6;\n if ($[12] !== onError) {\n t6 = error => {\n onError?.(error instanceof Error ? error : new Error(String(error)));\n };\n $[12] = onError;\n $[13] = t6;\n } else {\n t6 = $[13];\n }\n let t7;\n if ($[14] !== mutationFn || $[15] !== t5 || $[16] !== t6) {\n t7 = {\n mutationFn,\n onSuccess: t5,\n onError: t6\n };\n $[14] = mutationFn;\n $[15] = t5;\n $[16] = t6;\n $[17] = t7;\n } else {\n t7 = $[17];\n }\n const mutation = useMutation(t7);\n const t8 = mutation.error as Error | null;\n let t9;\n if ($[18] !== mutation.data || $[19] !== mutation.isPending || $[20] !== mutation.mutate || $[21] !== mutation.mutateAsync || $[22] !== mutation.reset || $[23] !== t8) {\n t9 = {\n mutate: mutation.mutate,\n mutateAsync: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: t8,\n reset: mutation.reset,\n data: mutation.data\n };\n $[18] = mutation.data;\n $[19] = mutation.isPending;\n $[20] = mutation.mutate;\n $[21] = mutation.mutateAsync;\n $[22] = mutation.reset;\n $[23] = t8;\n $[24] = t9;\n } else {\n t9 = $[24];\n }\n return t9;\n}\nexport default useDbUpsert;","import { c as _c } from \"react/compiler-runtime\";\n/**\n * V3 useDbDelete Hook\n *\n * React hook for deleting records from a table using the V3 adapter pattern.\n * Integrates with React Query for mutation management, cache invalidation,\n * and optional optimistic deletes.\n */\n\nimport { useCallback } from \"react\";\nimport { useMutation, useQueryClient } from \"@tanstack/react-query\";\nimport { useDataLayerCore } from \"./useDataLayer\";\n\n/**\n * Options for useDbDelete hook\n */\nexport interface UseDbDeleteOptions {\n /** Callback when delete succeeds */\n onSuccess?: () => void;\n /** Callback when delete fails */\n onError?: (error: Error) => void;\n /** Tables to invalidate after successful delete */\n invalidateTables?: string[];\n /** Enable optimistic delete */\n optimistic?: boolean;\n}\n\n/**\n * Result from useDbDelete hook\n */\nexport interface UseDbDeleteResult {\n /** Trigger delete (fire and forget) */\n mutate: (id: string) => void;\n /** Trigger delete and await completion */\n mutateAsync: (id: string) => Promise<void>;\n /** Whether mutation is in progress */\n isPending: boolean;\n /** Mutation error if any */\n error: Error | null;\n /** Reset mutation state */\n reset: () => void;\n}\n\n/**\n * Hook for deleting records from a table\n *\n * Uses the V3 adapter pattern to route deletes to the appropriate backend\n * (PowerSync, Supabase, or Cached) based on table configuration.\n *\n * @param table - The table name to delete from\n * @param options - Optional configuration for callbacks, cache invalidation, and optimistic deletes\n * @returns Mutation result with mutate/mutateAsync functions\n *\n * @example\n * ```typescript\n * const { mutateAsync, isPending } = useDbDelete(\"Task\");\n * await mutateAsync(taskId);\n * ```\n *\n * @example\n * ```typescript\n * // With optimistic delete for instant UI feedback\n * const { mutate } = useDbDelete(\"Comment\", {\n * optimistic: true,\n * onSuccess: () => console.log(\"Deleted successfully\"),\n * onError: (error) => console.error(\"Delete failed:\", error),\n * invalidateTables: [\"Comment\", \"Post\"],\n * });\n *\n * // Immediately removes from UI, rolls back on failure\n * mutate(commentId);\n * ```\n */\nexport function useDbDelete(table, t0) {\n const $ = _c(31);\n let t1;\n if ($[0] !== t0) {\n t1 = t0 === undefined ? {} : t0;\n $[0] = t0;\n $[1] = t1;\n } else {\n t1 = $[1];\n }\n const options = t1;\n const {\n registry\n } = useDataLayerCore();\n const queryClient = useQueryClient();\n const {\n onSuccess,\n onError,\n invalidateTables: t2,\n optimistic: t3\n } = options;\n let t4;\n if ($[2] !== t2 || $[3] !== table) {\n t4 = t2 === undefined ? [table] : t2;\n $[2] = t2;\n $[3] = table;\n $[4] = t4;\n } else {\n t4 = $[4];\n }\n const invalidateTables = t4;\n const optimistic = t3 === undefined ? false : t3;\n let t5;\n if ($[5] !== registry || $[6] !== table) {\n t5 = async id => {\n const adapter = registry.getAdapter(table, \"write\");\n await adapter.delete(table, id);\n };\n $[5] = registry;\n $[6] = table;\n $[7] = t5;\n } else {\n t5 = $[7];\n }\n const mutationFn = t5;\n let t6;\n if ($[8] !== optimistic || $[9] !== queryClient || $[10] !== table) {\n t6 = optimistic ? async id_0 => {\n await queryClient.cancelQueries({\n predicate: query => query.queryKey[0] === \"v3\" && query.queryKey[2] === table\n });\n const previousData = queryClient.getQueriesData({\n predicate: query_0 => query_0.queryKey[0] === \"v3\" && query_0.queryKey[2] === table\n });\n queryClient.setQueriesData({\n predicate: query_1 => query_1.queryKey[0] === \"v3\" && query_1.queryKey[2] === table\n }, old => {\n if (!old?.data) {\n return old;\n }\n return {\n ...old,\n data: old.data.filter(item => item.id !== id_0)\n };\n });\n return {\n previousData\n };\n } : undefined;\n $[8] = optimistic;\n $[9] = queryClient;\n $[10] = table;\n $[11] = t6;\n } else {\n t6 = $[11];\n }\n let t7;\n if ($[12] !== invalidateTables || $[13] !== onSuccess || $[14] !== queryClient) {\n t7 = () => {\n invalidateTables.forEach(t => {\n queryClient.invalidateQueries({\n predicate: query_2 => query_2.queryKey[0] === \"v3\" && query_2.queryKey[2] === t\n });\n });\n onSuccess?.();\n };\n $[12] = invalidateTables;\n $[13] = onSuccess;\n $[14] = queryClient;\n $[15] = t7;\n } else {\n t7 = $[15];\n }\n let t8;\n if ($[16] !== onError || $[17] !== optimistic || $[18] !== queryClient) {\n t8 = (error, _id, context) => {\n if (optimistic && context?.previousData) {\n context.previousData.forEach(t9 => {\n const [queryKey, data] = t9;\n queryClient.setQueryData(queryKey, data);\n });\n }\n onError?.(error instanceof Error ? error : new Error(String(error)));\n };\n $[16] = onError;\n $[17] = optimistic;\n $[18] = queryClient;\n $[19] = t8;\n } else {\n t8 = $[19];\n }\n let t9;\n if ($[20] !== mutationFn || $[21] !== t6 || $[22] !== t7 || $[23] !== t8) {\n t9 = {\n mutationFn,\n onMutate: t6,\n onSuccess: t7,\n onError: t8\n };\n $[20] = mutationFn;\n $[21] = t6;\n $[22] = t7;\n $[23] = t8;\n $[24] = t9;\n } else {\n t9 = $[24];\n }\n const mutation = useMutation(t9);\n const t10 = mutation.error as Error | null;\n let t11;\n if ($[25] !== mutation.isPending || $[26] !== mutation.mutate || $[27] !== mutation.mutateAsync || $[28] !== mutation.reset || $[29] !== t10) {\n t11 = {\n mutate: mutation.mutate,\n mutateAsync: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: t10,\n reset: mutation.reset\n };\n $[25] = mutation.isPending;\n $[26] = mutation.mutate;\n $[27] = mutation.mutateAsync;\n $[28] = mutation.reset;\n $[29] = t10;\n $[30] = t11;\n } else {\n t11 = $[30];\n }\n return t11;\n}\nexport default useDbDelete;","/**\n * V3 useDbInfiniteQuery Hook\n *\n * React hook for querying records with infinite scroll pagination.\n * Works identically whether PowerSync or Supabase is the backend.\n * Uses React Query's useInfiniteQuery for state management and caching.\n *\n * Types are automatically inferred from table names when you augment\n * the DatabaseTypes interface with your app's Database type.\n *\n * @example\n * // In your app's types/db.d.ts:\n * declare module \"@pol-studios/db\" {\n * interface DatabaseTypes {\n * database: import(\"@/database.types\").Database;\n * }\n * }\n *\n * // Then usage auto-infers types:\n * const { data, fetchNextPage, hasNextPage } = useDbInfiniteQuery(\"EquipmentFixtureUnit\", {\n * pageSize: 20,\n * orderBy: [{ field: \"createdAt\", direction: \"desc\" }],\n * });\n */\n\nimport { useMemo, useCallback, useEffect } from \"react\";\nimport { useInfiniteQuery, InfiniteData } from \"@tanstack/react-query\";\nimport { useDataLayerCore } from \"./useDataLayer\";\nimport type { QueryOptions, WhereClause } from \"../core/types\";\nimport { devLog, devWarn } from \"../utils/dev-log\";\n\n// =============================================================================\n// Module Augmentation Interface\n// =============================================================================\n\n/**\n * Augment this interface in your app to enable automatic type inference.\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface DatabaseTypes {}\n\n// =============================================================================\n// Database Type Helpers\n// =============================================================================\n\n/**\n * The configured Database type, or a generic fallback\n */\ntype ConfiguredDatabase = DatabaseTypes extends {\n database: infer DB;\n} ? DB : GenericSchema;\n\n/**\n * Generic schema structure for fallback\n */\ntype GenericSchema = {\n public: {\n Tables: Record<string, {\n Row: Record<string, unknown>;\n }>;\n Views: Record<string, {\n Row: Record<string, unknown>;\n }>;\n };\n [schema: string]: {\n Tables: Record<string, {\n Row: Record<string, unknown>;\n }>;\n Views?: Record<string, {\n Row: Record<string, unknown>;\n }>;\n };\n};\n\n/**\n * Default schema from Database (usually \"public\")\n */\ntype DefaultSchema = ConfiguredDatabase extends {\n public: infer S;\n} ? S : never;\n\n/**\n * Extract all valid table names from the default schema\n */\nexport type PublicTableNames = DefaultSchema extends {\n Tables: infer T;\n} ? keyof T & string : string;\n\n/**\n * Extract all valid schema names\n */\nexport type SchemaNames = keyof ConfiguredDatabase & string;\n\n/**\n * Extract table names for a specific schema\n */\nexport type SchemaTableNames<S extends string> = ConfiguredDatabase extends { [K in S]: {\n Tables: infer T;\n} } ? keyof T & string : string;\n\n/**\n * Build dot notation strings for all schema.table combinations\n */\ntype SchemaDotTable = { [S in SchemaNames]: S extends \"public\" ? never : `${S}.${SchemaTableNames<S>}` }[SchemaNames];\n\n/**\n * Table identifier - provides autocomplete for valid table names\n */\nexport type TableIdentifier = PublicTableNames | SchemaDotTable | { [S in Exclude<SchemaNames, \"public\">]: {\n schema: S;\n table: SchemaTableNames<S>;\n} }[Exclude<SchemaNames, \"public\">];\n\n/**\n * Resolve row type from a table identifier\n */\nexport type ResolveRowType<T extends TableIdentifier> = T extends string ? T extends `${infer Schema}.${infer Table}` ? ConfiguredDatabase extends { [K in Schema]: {\n Tables: { [K2 in Table]: {\n Row: infer R;\n } };\n} } ? R : Record<string, unknown> : DefaultSchema extends {\n Tables: { [K in T]: {\n Row: infer R;\n } };\n} ? R : DefaultSchema extends {\n Views: { [K in T]: {\n Row: infer R;\n } };\n} ? R : Record<string, unknown> : T extends {\n schema: infer S;\n table: infer TN;\n} ? S extends string ? TN extends string ? ConfiguredDatabase extends { [K in S]: {\n Tables: { [K2 in TN]: {\n Row: infer R;\n } };\n} } ? R : Record<string, unknown> : Record<string, unknown> : Record<string, unknown> : Record<string, unknown>;\n\n// =============================================================================\n// Types\n// =============================================================================\n\n/**\n * Options for useDbInfiniteQuery hook\n */\nexport interface UseDbInfiniteQueryOptions extends Omit<QueryOptions, \"limit\" | \"offset\" | \"enabled\"> {\n /** Whether the query is enabled (default: true) */\n enabled?: boolean;\n /** React Query stale time in ms (default: 30000) */\n staleTime?: number;\n /** Whether to refetch on window focus (default: true) */\n refetchOnWindowFocus?: boolean;\n /** Number of items per page (default: 50) */\n pageSize?: number;\n /** Text to search for */\n searchText?: string;\n /** Fields to search in when searchText is provided */\n searchFields?: string[];\n}\n\n/**\n * Result from useDbInfiniteQuery hook\n */\nexport interface UseDbInfiniteQueryResult<T> {\n /** Flattened array of all loaded data */\n data: T[] | undefined;\n /** Whether query is loading (initial load) */\n isLoading: boolean;\n /** Whether query is in pending state */\n isPending: boolean;\n /** Whether query is currently fetching (including refetch) */\n isFetching: boolean;\n /** Query error if any */\n error: Error | null;\n /** Function to fetch the next page */\n fetchNextPage: () => Promise<void>;\n /** Whether there are more pages to load */\n hasNextPage: boolean;\n /** Whether currently fetching the next page */\n isFetchingNextPage: boolean;\n /** Total count of items (if available) */\n count?: number;\n /** Refetch all pages */\n refetch: () => Promise<void>;\n}\n\n/**\n * Internal page result type\n */\ninterface PageResult<T> {\n data: T[];\n count?: number;\n}\n\n// =============================================================================\n// Helper Functions\n// =============================================================================\n\n/**\n * Build a query key for React Query infinite queries\n */\nfunction buildInfiniteQueryKey(table: string, options: UseDbInfiniteQueryOptions): unknown[] {\n return [\"v3\", \"infinite-query\", table, options.select ?? \"*\", JSON.stringify(options.where ?? {}), JSON.stringify(options.orderBy ?? []), options.pageSize ?? 50, options.searchText ?? \"\", JSON.stringify(options.searchFields ?? [])];\n}\n\n/**\n * Serialize query options for dependency tracking\n */\nfunction serializeInfiniteQueryOptions(options: UseDbInfiniteQueryOptions): string {\n return JSON.stringify({\n select: options.select,\n where: options.where,\n orderBy: options.orderBy,\n pageSize: options.pageSize,\n searchText: options.searchText,\n searchFields: options.searchFields\n });\n}\n\n/**\n * Helper to resolve table name from TableIdentifier\n */\nfunction resolveTableName(table: TableIdentifier): string {\n if (typeof table === \"string\") {\n return table;\n }\n return `${table.schema}.${table.table}`;\n}\n\n/**\n * Build search where clause from searchText and searchFields\n */\nfunction buildSearchWhereClause(searchText: string, searchFields: string[], existingWhere?: WhereClause): WhereClause {\n const searchWhere: WhereClause = {};\n if (searchFields.length === 1) {\n searchWhere[searchFields[0]] = {\n like: `%${searchText}%`\n };\n } else if (searchFields.length > 1) {\n searchWhere[searchFields[0]] = {\n like: `%${searchText}%`\n };\n }\n return {\n ...existingWhere,\n ...searchWhere\n };\n}\n\n// =============================================================================\n// Hook Implementation\n// =============================================================================\n\n/**\n * Hook for querying records with infinite scroll pagination\n *\n * @param table - Table name (string) or { schema, table } object\n * @param options - Query options (select, where, orderBy, pageSize, searchText, etc.)\n * @returns Query result with data, loading states, pagination controls, and refetch function\n *\n * @example\n * // Basic infinite query - types auto-inferred from table name\n * const { data, fetchNextPage, hasNextPage } = useDbInfiniteQuery(\"EquipmentFixtureUnit\");\n *\n * @example\n * // With search and pagination\n * const { data, fetchNextPage, hasNextPage, isFetchingNextPage } = useDbInfiniteQuery(\"Task\", {\n * pageSize: 20,\n * searchText: searchQuery,\n * searchFields: [\"name\", \"description\"],\n * orderBy: [{ field: \"createdAt\", direction: \"desc\" }],\n * });\n *\n * @example\n * // In a FlatList or similar\n * <FlatList\n * data={data}\n * onEndReached={() => hasNextPage && fetchNextPage()}\n * ListFooterComponent={isFetchingNextPage ? <Spinner /> : null}\n * />\n */\nexport function useDbInfiniteQuery<T extends TableIdentifier>(table: T, options?: UseDbInfiniteQueryOptions): UseDbInfiniteQueryResult<ResolveRowType<T>>;\n\n/**\n * Overload for explicit type parameter (backwards compatibility)\n */\nexport function useDbInfiniteQuery<T>(table: string, options?: UseDbInfiniteQueryOptions): UseDbInfiniteQueryResult<T>;\nexport function useDbInfiniteQuery<T>(table: TableIdentifier, options: UseDbInfiniteQueryOptions = {}): UseDbInfiniteQueryResult<T> {\n const tableName = resolveTableName(table);\n const {\n registry\n } = useDataLayerCore();\n const {\n enabled = true,\n staleTime = 30000,\n refetchOnWindowFocus = true,\n pageSize = 50,\n searchText,\n searchFields,\n ...queryOptions\n } = options;\n\n // Get adapter for this table\n // No isInitialized check needed - if we get here, core context exists = initialized\n const adapter = useMemo(() => {\n try {\n return registry.getAdapter(tableName);\n } catch {\n return null;\n }\n }, [registry, tableName]);\n\n // Serialize options for stable dependency tracking\n const serializedOptions = useMemo(() => serializeInfiniteQueryOptions(options), [options.select, options.where, options.orderBy, options.pageSize, options.searchText, options.searchFields]);\n\n // Build query key\n const queryKey = useMemo(() => buildInfiniteQueryKey(tableName, options), [tableName, serializedOptions]);\n\n // Build the where clause including search conditions\n const effectiveWhere = useMemo(() => {\n if (searchText && searchFields && searchFields.length > 0) {\n return buildSearchWhereClause(searchText, searchFields, queryOptions.where);\n }\n return queryOptions.where;\n }, [searchText, searchFields, queryOptions.where]);\n\n // Memoize base query options\n const memoizedQueryOptions = useMemo(() => ({\n select: queryOptions.select,\n where: effectiveWhere,\n orderBy: queryOptions.orderBy\n }), [queryOptions.select, effectiveWhere, queryOptions.orderBy]);\n\n // Execute infinite query with React Query\n const infiniteQuery = useInfiniteQuery<PageResult<T>, Error, InfiniteData<PageResult<T>, number>, unknown[], number>({\n queryKey,\n queryFn: async ({\n pageParam\n }) => {\n if (!adapter) {\n throw new Error(`Adapter not available for table: ${tableName}`);\n }\n const offset = (pageParam - 1) * pageSize;\n const result = await adapter.query<T>(tableName, {\n ...memoizedQueryOptions,\n limit: pageSize,\n offset\n });\n return {\n data: result.data ?? [],\n count: result.count\n };\n },\n initialPageParam: 1,\n getNextPageParam: (lastPage, allPages) => {\n const totalLoaded = allPages.reduce((sum, page) => sum + page.data.length, 0);\n const totalCount = lastPage.count;\n if (totalCount !== undefined && totalLoaded >= totalCount) {\n return undefined;\n }\n if (lastPage.data.length < pageSize) {\n return undefined;\n }\n return allPages.length + 1;\n },\n enabled: enabled && adapter !== null,\n staleTime,\n refetchOnWindowFocus\n });\n\n // Flatten all pages into a single data array\n const flattenedData = useMemo(() => {\n if (!infiniteQuery.data?.pages) return undefined;\n return infiniteQuery.data.pages.flatMap(page_0 => page_0.data);\n }, [infiniteQuery.data?.pages]);\n\n // Get total count from the last page\n const count = useMemo(() => {\n if (!infiniteQuery.data?.pages || infiniteQuery.data.pages.length === 0) {\n return undefined;\n }\n return infiniteQuery.data.pages[infiniteQuery.data.pages.length - 1].count;\n }, [infiniteQuery.data?.pages]);\n\n // Build fetchNextPage function\n const fetchNextPage = useCallback(async () => {\n await infiniteQuery.fetchNextPage();\n }, [infiniteQuery]);\n\n // Build refetch function\n const refetch = useCallback(async () => {\n await infiniteQuery.refetch();\n }, [infiniteQuery]);\n\n // Dev logging for debugging\n useEffect(() => {\n const adapterName = adapter?.name ?? \"unknown\";\n\n // Log errors\n if (infiniteQuery.isError && infiniteQuery.error) {\n devWarn(\"useDbInfiniteQuery\", `${tableName} via ${adapterName}: Error - ${infiniteQuery.error.message}`);\n }\n\n // Log empty results (only after successful fetch, not during loading)\n if (infiniteQuery.isSuccess && flattenedData?.length === 0) {\n devLog(\"useDbInfiniteQuery\", `${tableName} via ${adapterName}: 0 results`);\n }\n }, [infiniteQuery.isError, infiniteQuery.error, infiniteQuery.isSuccess, flattenedData, tableName, adapter]);\n return {\n data: flattenedData,\n isLoading: infiniteQuery.isLoading,\n isPending: infiniteQuery.isPending,\n isFetching: infiniteQuery.isFetching,\n error: infiniteQuery.error as Error | null,\n fetchNextPage,\n hasNextPage: infiniteQuery.hasNextPage ?? false,\n isFetchingNextPage: infiniteQuery.isFetchingNextPage,\n count,\n refetch\n };\n}\nexport default useDbInfiniteQuery;","import { c as _c } from \"react/compiler-runtime\";\n/**\n * V3 useDbCount Hook\n *\n * React hook for counting records in a table.\n * Works with the data layer using either PowerSync or Supabase backend.\n */\n\nimport { useMemo, useCallback, useEffect } from \"react\";\nimport { useQuery } from \"@tanstack/react-query\";\nimport { useDataLayerCore } from \"./useDataLayer\";\nimport type { WhereClause } from \"../core/types\";\nimport { devWarn } from \"../utils/dev-log\";\n\n// =============================================================================\n// Types\n// =============================================================================\n\n/**\n * Options for useDbCount hook\n */\nexport interface UseDbCountOptions {\n /** Filter conditions */\n where?: WhereClause;\n /** Whether the query is enabled (default: true) */\n enabled?: boolean;\n /** React Query stale time in ms (default: 30000) */\n staleTime?: number;\n}\n\n/**\n * Result from useDbCount hook\n */\nexport interface UseDbCountResult {\n /** The count value */\n count: number | undefined;\n /** Whether query is loading */\n isLoading: boolean;\n /** Whether query is fetching */\n isFetching: boolean;\n /** Query error if any */\n error: Error | null;\n /** Refetch the count */\n refetch: () => Promise<void>;\n}\n\n// =============================================================================\n// Hook Implementation\n// =============================================================================\n\n/**\n * Hook for counting records in a table\n *\n * @param table - The table name to count\n * @param options - Count options (where filter, enabled)\n * @returns Count result with loading states\n *\n * @example\n * // Simple count\n * const { count, isLoading } = useDbCount(\"EquipmentFixtureUnit\");\n *\n * @example\n * // Count with filter\n * const { count } = useDbCount(\"EquipmentFixtureUnit\", {\n * where: { projectDatabaseId: 123 },\n * });\n */\nexport function useDbCount(table, t0) {\n const $ = _c(37);\n let t1;\n if ($[0] !== t0) {\n t1 = t0 === undefined ? {} : t0;\n $[0] = t0;\n $[1] = t1;\n } else {\n t1 = $[1];\n }\n const options = t1;\n const {\n registry\n } = useDataLayerCore();\n const {\n enabled: t2,\n staleTime: t3,\n where\n } = options;\n const enabled = t2 === undefined ? true : t2;\n const staleTime = t3 === undefined ? 30000 : t3;\n let t4;\n try {\n let t5;\n if ($[2] !== registry || $[3] !== table) {\n t5 = registry.getAdapter(table);\n $[2] = registry;\n $[3] = table;\n $[4] = t5;\n } else {\n t5 = $[4];\n }\n t4 = t5;\n } catch {\n t4 = null;\n }\n const adapter = t4;\n let t5;\n if ($[5] !== where) {\n t5 = JSON.stringify(where ?? {});\n $[5] = where;\n $[6] = t5;\n } else {\n t5 = $[6];\n }\n let t6;\n if ($[7] !== t5 || $[8] !== table) {\n t6 = [\"v3\", \"count\", table, t5];\n $[7] = t5;\n $[8] = table;\n $[9] = t6;\n } else {\n t6 = $[9];\n }\n const queryKey = t6;\n let t7;\n if ($[10] !== adapter || $[11] !== table || $[12] !== where) {\n t7 = async () => {\n if (!adapter) {\n throw new Error(`Adapter not available for table: ${table}`);\n }\n const result = await adapter.query(table, {\n where,\n select: \"id\"\n });\n return result.count ?? result.data.length;\n };\n $[10] = adapter;\n $[11] = table;\n $[12] = where;\n $[13] = t7;\n } else {\n t7 = $[13];\n }\n const queryFn = t7;\n const t8 = enabled && adapter !== null;\n let t9;\n if ($[14] !== queryFn || $[15] !== queryKey || $[16] !== staleTime || $[17] !== t8) {\n t9 = {\n queryKey,\n queryFn,\n enabled: t8,\n staleTime\n };\n $[14] = queryFn;\n $[15] = queryKey;\n $[16] = staleTime;\n $[17] = t8;\n $[18] = t9;\n } else {\n t9 = $[18];\n }\n const query = useQuery(t9);\n let t10;\n if ($[19] !== adapter?.name || $[20] !== query.error || $[21] !== query.isError || $[22] !== table) {\n t10 = () => {\n if (query.isError && query.error) {\n const adapterName = adapter?.name ?? \"unknown\";\n devWarn(\"useDbCount\", `${table} via ${adapterName}: Error - ${query.error.message}`);\n }\n };\n $[19] = adapter?.name;\n $[20] = query.error;\n $[21] = query.isError;\n $[22] = table;\n $[23] = t10;\n } else {\n t10 = $[23];\n }\n let t11;\n if ($[24] !== adapter || $[25] !== query.error || $[26] !== query.isError || $[27] !== table) {\n t11 = [query.isError, query.error, table, adapter];\n $[24] = adapter;\n $[25] = query.error;\n $[26] = query.isError;\n $[27] = table;\n $[28] = t11;\n } else {\n t11 = $[28];\n }\n useEffect(t10, t11);\n let t12;\n if ($[29] !== query) {\n t12 = async () => {\n await query.refetch();\n };\n $[29] = query;\n $[30] = t12;\n } else {\n t12 = $[30];\n }\n const refetch = t12;\n const t13 = query.error as Error | null;\n let t14;\n if ($[31] !== query.data || $[32] !== query.isFetching || $[33] !== query.isLoading || $[34] !== refetch || $[35] !== t13) {\n t14 = {\n count: query.data,\n isLoading: query.isLoading,\n isFetching: query.isFetching,\n error: t13,\n refetch\n };\n $[31] = query.data;\n $[32] = query.isFetching;\n $[33] = query.isLoading;\n $[34] = refetch;\n $[35] = t13;\n $[36] = t14;\n } else {\n t14 = $[36];\n }\n return t14;\n}\nexport default useDbCount;","import { c as _c } from \"react/compiler-runtime\";\n/**\n * V3 useSyncStatus Hook\n *\n * Provides sync status information from the data layer.\n * Returns default \"always synced\" status when PowerSync is not available.\n *\n * Uses the split context architecture for optimal performance.\n */\n\nimport { useState, useEffect, useContext } from \"react\";\nimport { DataLayerStatusContext, DataLayerCoreContext } from \"../providers/DataLayerContext\";\nimport type { SyncStatus } from \"../core/types\";\n\n/**\n * Default sync status when PowerSync is not available\n */\nconst defaultSyncStatus: SyncStatus = {\n isConnected: true,\n // Supabase-only mode is always \"connected\" when online\n isSyncing: false,\n lastSyncedAt: null,\n pendingUploads: 0,\n error: null\n};\n\n/**\n * Hook to get the current sync status\n *\n * When PowerSync is not available, returns a default \"always synced\" status.\n *\n * This hook uses the split context architecture - it only subscribes to\n * status changes, not core value changes.\n *\n * @example\n * const { isSyncing, pendingUploads, isConnected } = useSyncStatus();\n *\n * if (pendingUploads > 0) {\n * console.log(`${pendingUploads} changes waiting to sync`);\n * }\n */\nexport function useSyncStatus() {\n const $ = _c(6);\n const statusContext = useContext(DataLayerStatusContext);\n const coreContext = useContext(DataLayerCoreContext);\n if (!statusContext || !coreContext) {\n throw new Error(\"useSyncStatus must be used within a DataLayerProvider. Make sure you have wrapped your app with <DataLayerProvider>.\");\n }\n const {\n syncStatus,\n status\n } = statusContext;\n const {\n powerSync\n } = coreContext;\n const [currentStatus, setCurrentStatus] = useState(syncStatus);\n let t0;\n let t1;\n if ($[0] !== powerSync || $[1] !== status.currentBackend || $[2] !== status.isOnline || $[3] !== syncStatus) {\n t0 = () => {\n if (powerSync && status.currentBackend === \"powersync\") {\n setCurrentStatus(syncStatus);\n } else {\n setCurrentStatus({\n ...defaultSyncStatus,\n isConnected: status.isOnline\n });\n }\n };\n t1 = [syncStatus, status.currentBackend, status.isOnline, powerSync];\n $[0] = powerSync;\n $[1] = status.currentBackend;\n $[2] = status.isOnline;\n $[3] = syncStatus;\n $[4] = t0;\n $[5] = t1;\n } else {\n t0 = $[4];\n t1 = $[5];\n }\n useEffect(t0, t1);\n return currentStatus;\n}\nexport default useSyncStatus;","import { c as _c } from \"react/compiler-runtime\";\n/**\n * V3 useSyncControl Hook\n *\n * Provides sync control functions from the data layer.\n * Returns no-op functions when PowerSync is not available.\n *\n * Uses the split context architecture for optimal performance.\n */\n\nimport { useMemo, useContext } from \"react\";\nimport { DataLayerCoreContext } from \"../providers/DataLayerContext\";\nimport type { SyncControl } from \"../core/types\";\n\n/**\n * Hook to get sync controls for PowerSync\n *\n * When PowerSync is not available, all methods are no-ops that log a warning.\n *\n * PERFORMANCE: This hook only subscribes to DataLayerCoreContext (stable values),\n * NOT DataLayerStatusContext. This means components using useSyncControl() will\n * NOT re-render when network status or sync status changes.\n *\n * @example\n * const { triggerSync, startLiveSync, stopLiveSync } = useSyncControl();\n *\n * // Manually trigger a sync\n * await triggerSync();\n *\n * // Start/stop live sync\n * await startLiveSync();\n * stopLiveSync();\n */\nexport function useSyncControl() {\n const $ = _c(1);\n const coreContext = useContext(DataLayerCoreContext);\n if (!coreContext) {\n throw new Error(\"useSyncControl must be used within a DataLayerProvider. Make sure you have wrapped your app with <DataLayerProvider>.\");\n }\n const {\n syncControl,\n powerSync\n } = coreContext;\n const isPowerSyncActive = powerSync !== null;\n let t0;\n if ($[0] === Symbol.for(\"react.memo_cache_sentinel\")) {\n t0 = {\n triggerSync: _temp,\n startLiveSync: _temp2,\n stopLiveSync: _temp3,\n setScope: _temp4,\n pauseAutoRetry: _temp5,\n resumeAutoRetry: _temp6,\n isAutoRetryPaused: false,\n addPendingMutation: _temp7,\n removePendingMutation: _temp8\n };\n $[0] = t0;\n } else {\n t0 = $[0];\n }\n const noOpControls = t0;\n let t1;\n bb0: {\n if (isPowerSyncActive) {\n t1 = syncControl;\n break bb0;\n }\n t1 = noOpControls;\n }\n const controls = t1;\n return controls;\n}\nfunction _temp8() {}\nfunction _temp7() {}\nfunction _temp6() {\n console.warn(\"[useSyncControl] resumeAutoRetry called but PowerSync is not available\");\n}\nfunction _temp5() {\n console.warn(\"[useSyncControl] pauseAutoRetry called but PowerSync is not available\");\n}\nasync function _temp4(_scopeName, _values) {\n console.warn(\"[useSyncControl] setScope called but PowerSync is not available\");\n}\nfunction _temp3() {\n console.warn(\"[useSyncControl] stopLiveSync called but PowerSync is not available\");\n}\nasync function _temp2() {\n console.warn(\"[useSyncControl] startLiveSync called but PowerSync is not available\");\n}\nasync function _temp() {\n console.warn(\"[useSyncControl] triggerSync called but PowerSync is not available\");\n}\nexport default useSyncControl;","import { c as _c } from \"react/compiler-runtime\";\n/**\n * V3 useOnlineStatus Hook\n *\n * Provides online/connection status information.\n * Uses DataLayerProvider's status as the SINGLE source of truth.\n *\n * On React Native: status.isOnline comes from PowerSync platform adapter (NetInfo)\n * On Web: status.isOnline comes from browser navigator.onLine\n */\n\nimport { useMemo } from \"react\";\nimport { useDataLayerCore, useDataLayerStatus } from \"./useDataLayer\";\n\n/**\n * Online status information\n */\nexport interface OnlineStatus {\n /** Whether the device has network connectivity */\n isOnline: boolean;\n /** Whether PowerSync is connected (false if using Supabase-only) */\n isConnected: boolean;\n /** Current backend being used */\n backend: \"powersync\" | \"supabase\" | null;\n}\n\n/**\n * Hook to get online/connection status\n *\n * Uses DataLayerProvider's status as the single source of truth:\n * - On React Native: isOnline comes from PowerSync platform adapter (NetInfo)\n * - On Web: isOnline comes from browser navigator.onLine\n *\n * @example\n * const { isOnline, isConnected, backend } = useOnlineStatus();\n *\n * if (!isOnline) {\n * return <OfflineBanner />;\n * }\n */\nexport function useOnlineStatus() {\n const $ = _c(4);\n const {\n powerSync\n } = useDataLayerCore();\n const {\n status\n } = useDataLayerStatus();\n const t0 = powerSync !== null && status.powerSyncStatus === \"available\";\n let t1;\n if ($[0] !== status.currentBackend || $[1] !== status.isOnline || $[2] !== t0) {\n t1 = {\n isOnline: status.isOnline,\n isConnected: t0,\n backend: status.currentBackend\n };\n $[0] = status.currentBackend;\n $[1] = status.isOnline;\n $[2] = t0;\n $[3] = t1;\n } else {\n t1 = $[3];\n }\n return t1;\n}\nexport default useO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Q,OAAO,oBAAoB;AAC5D,MAAI;AACJ,MAAI,EAAE,CAAC,MAAM,OAAO,kBAAkB,EAAE,CAAC,MAAM,OAAO,YAAY,EAAE,CAAC,MAAM,IAAI;AAC7E,SAAK;AAAA,MACH,UAAU,OAAO;AAAA,MACjB,aAAa;AAAA,MACb,SAAS,OAAO;AAAA,IAClB;AACA,MAAE,CAAC,IAAI,OAAO;AACd,MAAE,CAAC,IAAI,OAAO;AACd,MAAE,CAAC,IAAI;AACP,MAAE,CAAC,IAAI;AAAA,EACT,OAAO;AACL,SAAK,EAAE,CAAC;AAAA,EACV;AACA,SAAO;AACT;","names":["useCallback","useMemo","useEffect","useQuery","useMemo","useCallback","useQuery","result","useEffect","_c","useMutation","useQueryClient","_c","useQueryClient","t9","useMutation","_c","useMutation","useQueryClient","_c","useQueryClient","useMutation","_c","useMutation","useQueryClient","_c","useQueryClient","t9","useMutation","useMemo","useCallback","useEffect","useMemo","useCallback","useEffect","_c","useEffect","useQuery","_c","t5","useQuery","useEffect","_c","useState","useEffect","_c","useState","useEffect","_c","useContext","_c","useContext","_c","_c"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/providers/DataLayerContext.ts","../src/hooks/useDataLayer.ts","../src/hooks/useDbQuery.ts","../src/utils/dev-log.ts"],"sourcesContent":["/**\n * V3 Data Layer Context\n *\n * Defines the React context and types for the V3 data layer provider.\n * This context provides access to adapters, sync status, and core instances.\n *\n * PERFORMANCE OPTIMIZATION:\n * The context is split into two separate contexts to prevent unnecessary re-renders:\n * - DataLayerCoreContext: Stable values that don't change after initialization\n * - DataLayerStatusContext: Dynamic values that change during runtime\n *\n * The original DataLayerContext is kept for backward compatibility.\n */\n\nimport { createContext } from \"react\";\nimport type { SupabaseClient } from \"@supabase/supabase-js\";\nimport type { QueryClient } from \"@tanstack/react-query\";\nimport type { AdapterRegistry } from \"../adapters/registry\";\nimport type { PowerSyncDatabase } from \"../query/executor\";\nimport type { DatabaseSchema, SyncStatus, SyncControl } from \"../core/types\";\nimport type { BackendStatus, AutoDetectionResult } from \"../adapters/auto-detector\";\nimport type { TableDataAdapter } from \"../adapters/types\";\n\n// =============================================================================\n// Status Types\n// =============================================================================\n\n/**\n * Status of the data layer initialization\n */\nexport interface DataLayerStatus {\n /** Whether the data layer is fully initialized */\n isInitialized: boolean;\n /** Current active backend */\n currentBackend: \"powersync\" | \"supabase\" | null;\n /** PowerSync connection status */\n powerSyncStatus: BackendStatus;\n /** Whether device is online */\n isOnline: boolean;\n /** Last auto-detection result */\n lastDetection: AutoDetectionResult | null;\n /** Initialization error if any */\n error: Error | null;\n /** Whether initial sync has completed (from PowerSync) */\n hasSynced: boolean;\n}\n\n// =============================================================================\n// Split Context Types (Performance Optimization)\n// =============================================================================\n\n/**\n * STABLE core context - values that don't change after initialization\n *\n * Use useDataLayerCore() to access these values in query/mutation hooks\n * to avoid re-renders when sync status changes.\n */\nexport interface DataLayerCoreContextValue {\n /** Adapter registry for getting table adapters */\n registry: AdapterRegistry;\n /** Get adapter for a specific table (defaults to 'read' operation) */\n getAdapter: (table: string, operation?: 'read' | 'write') => TableDataAdapter;\n /** PowerSync database instance (null when not available) */\n powerSync: PowerSyncDatabase | null;\n /** Supabase client (always available) */\n supabase: SupabaseClient;\n /** React Query client */\n queryClient: QueryClient;\n /** Database schema */\n schema: DatabaseSchema;\n /** Sync controls (for PowerSync, no-op for Supabase-only) - stable reference */\n syncControl: SyncControl;\n}\n\n/**\n * DYNAMIC status context - values that change during runtime\n *\n * Use useDataLayerStatus() for UI components that display sync status,\n * online indicator, etc. Components using this WILL re-render when status changes.\n */\nexport interface DataLayerStatusContextValue {\n /** Current status */\n status: DataLayerStatus;\n /** Sync status (for PowerSync, no-op for Supabase-only) */\n syncStatus: SyncStatus;\n}\n\n// =============================================================================\n// Combined Context Value Type (Backward Compatibility)\n// =============================================================================\n\n/**\n * Context value for the data layer (combines core and status)\n *\n * @deprecated Prefer using useDataLayerCore() or useDataLayerStatus() for better performance.\n * This combined interface is kept for backward compatibility.\n */\nexport interface DataLayerContextValue {\n /** Adapter registry for getting table adapters */\n registry: AdapterRegistry;\n\n /** Get adapter for a specific table (defaults to 'read' operation) */\n getAdapter: (table: string, operation?: 'read' | 'write') => TableDataAdapter;\n\n /** PowerSync database instance (null when not available) */\n powerSync: PowerSyncDatabase | null;\n\n /** Supabase client (always available) */\n supabase: SupabaseClient;\n\n /** React Query client */\n queryClient: QueryClient;\n\n /** Database schema */\n schema: DatabaseSchema;\n\n /** Current status */\n status: DataLayerStatus;\n\n /** Sync status (for PowerSync, no-op for Supabase-only) */\n syncStatus: SyncStatus;\n\n /** Sync controls (for PowerSync, no-op for Supabase-only) */\n syncControl: SyncControl;\n}\n\n// =============================================================================\n// Context Creation\n// =============================================================================\n\n/**\n * STABLE Core context - values that don't change after initialization\n *\n * Use useDataLayerCore() hook to access. Components consuming this context\n * will NOT re-render when sync status or network status changes.\n */\nexport const DataLayerCoreContext = createContext<DataLayerCoreContextValue | null>(null);\nDataLayerCoreContext.displayName = \"DataLayerCoreContext\";\n\n/**\n * DYNAMIC Status context - values that change during runtime\n *\n * Use useDataLayerStatus() hook to access. Components consuming this context\n * WILL re-render when sync status or network status changes.\n */\nexport const DataLayerStatusContext = createContext<DataLayerStatusContextValue | null>(null);\nDataLayerStatusContext.displayName = \"DataLayerStatusContext\";\n\n/**\n * Combined data layer context (backward compatibility)\n *\n * @deprecated Prefer using DataLayerCoreContext or DataLayerStatusContext for better performance.\n * Provides access to the V3 data layer throughout the React component tree.\n * Must be accessed via the useDataLayer hook or similar consumer.\n */\nexport const DataLayerContext = createContext<DataLayerContextValue | null>(null);\nDataLayerContext.displayName = \"DataLayerContext\";","/**\n * V3 Data Layer Hooks\n *\n * Provides access to the V3 data layer context for components.\n * This module provides three hooks for different use cases:\n *\n * - useDataLayerCore(): Stable values only (registry, adapters, clients)\n * Use in query/mutation hooks to avoid re-renders on status changes.\n *\n * - useDataLayerStatus(): Dynamic values only (status, syncStatus, syncControl)\n * Use for UI components that display sync status, online indicator, etc.\n *\n * - useDataLayer(): Combined access (backward compatible)\n * Use when you need both core and status values.\n */\n\nimport { useContext } from \"react\";\nimport { DataLayerContext, DataLayerCoreContext, DataLayerStatusContext, type DataLayerContextValue, type DataLayerCoreContextValue, type DataLayerStatusContextValue } from \"../providers/DataLayerContext\";\n\n// =============================================================================\n// PERFORMANCE-OPTIMIZED HOOKS (Recommended)\n// =============================================================================\n\n/**\n * Hook to access ONLY the stable core values (registry, adapters, clients)\n *\n * PERFORMANCE BENEFIT: Components using this hook will NOT re-render when\n * network status or sync status changes. Use this in query/mutation hooks.\n *\n * Provides access to:\n * - registry: Adapter registry for getting table adapters\n * - getAdapter: Function to get adapter for a specific table\n * - powerSync: PowerSync database instance (null when not available)\n * - supabase: Supabase client (always available)\n * - queryClient: React Query client\n * - schema: Database schema\n *\n * @throws Error if used outside of DataLayerProvider\n *\n * @example\n * const { getAdapter, supabase } = useDataLayerCore();\n * const adapter = getAdapter(\"Task\");\n * // This component won't re-render on sync status changes\n */\nexport function useDataLayerCore() {\n const context = useContext(DataLayerCoreContext);\n if (!context) {\n throw new Error(\"useDataLayerCore must be used within a DataLayerProvider. Make sure you have wrapped your app with <DataLayerProvider>.\");\n }\n return context;\n}\n\n/**\n * Hook to access ONLY the STABLE core context (optional version).\n * Returns null if DataLayerProvider is not present, rather than throwing.\n * Use this when you need graceful fallback behavior.\n *\n * @example\n * const dataLayerCore = useDataLayerCoreOptional();\n * if (dataLayerCore) {\n * // Use V3 adapter pattern\n * } else {\n * // Fall back to Supabase\n * }\n */\nexport function useDataLayerCoreOptional() {\n return useContext(DataLayerCoreContext);\n}\n\n/**\n * Hook to access ONLY the dynamic status values\n *\n * PERFORMANCE BENEFIT: Only components that actually need status information\n * will re-render when status changes. Use for UI components that display\n * sync status, online indicator, pending uploads count, etc.\n *\n * Provides access to:\n * - status: Current initialization and connection status\n * - syncStatus: Sync status for PowerSync\n * - syncControl: Sync controls for PowerSync\n *\n * @throws Error if used outside of DataLayerProvider\n *\n * @example\n * const { status, syncStatus } = useDataLayerStatus();\n *\n * return (\n * <StatusBar\n * isOnline={status.isOnline}\n * pendingUploads={syncStatus.pendingUploads}\n * />\n * );\n */\nexport function useDataLayerStatus() {\n const context = useContext(DataLayerStatusContext);\n if (!context) {\n throw new Error(\"useDataLayerStatus must be used within a DataLayerProvider. Make sure you have wrapped your app with <DataLayerProvider>.\");\n }\n return context;\n}\n\n// =============================================================================\n// BACKWARD COMPATIBLE HOOKS\n// =============================================================================\n\n/**\n * Hook to access the V3 data layer context (combined core + status)\n *\n * NOTE: Consider using useDataLayerCore() or useDataLayerStatus() instead\n * for better render performance. This hook re-renders on ALL status changes.\n *\n * Provides access to:\n * - registry: Adapter registry for getting table adapters\n * - getAdapter: Function to get adapter for a specific table\n * - powerSync: PowerSync database instance (null when not available)\n * - supabase: Supabase client (always available)\n * - queryClient: React Query client\n * - schema: Database schema\n * - status: Current initialization and connection status\n * - syncStatus: Sync status for PowerSync\n * - syncControl: Sync controls for PowerSync\n *\n * @throws Error if used outside of DataLayerProvider\n *\n * @example\n * const { getAdapter, status } = useDataLayer();\n *\n * if (status.isInitialized) {\n * const adapter = getAdapter(\"Task\");\n * // Use adapter...\n * }\n */\nexport function useDataLayer() {\n const context = useContext(DataLayerContext);\n if (!context) {\n throw new Error(\"useDataLayer must be used within a DataLayerProvider. Make sure you have wrapped your app with <DataLayerProvider>.\");\n }\n return context;\n}\n\n/**\n * Hook to safely access data layer context (returns null if not in provider)\n *\n * Use this when you need to check if the data layer is available\n * without throwing an error. Useful for conditional rendering or\n * components that may be rendered outside the provider context.\n *\n * @example\n * const dataLayer = useDataLayerOptional();\n *\n * if (dataLayer) {\n * // Safe to use data layer\n * } else {\n * // Render fallback UI\n * }\n */\nexport function useDataLayerOptional() {\n return useContext(DataLayerContext);\n}\nexport default useDataLayer;","/**\n * V3 useDbQuery Hook\n *\n * React hook for querying multiple records from a table.\n * Works identically whether PowerSync or Supabase is the backend.\n * Uses React Query for state management and caching.\n *\n * Types are automatically inferred from table names when you augment\n * the DatabaseTypes interface with your app's Database type.\n *\n * @example\n * // In your app's types/db.d.ts:\n * declare module \"@pol-studios/db\" {\n * interface DatabaseTypes {\n * database: import(\"@/database.types\").Database;\n * }\n * }\n *\n * // Then usage auto-infers types:\n * const { data } = useDbQuery(\"EquipmentFixtureUnit\", { ... });\n * // data is typed as Tables<\"EquipmentFixtureUnit\">[]\n */\n\nimport { useMemo, useEffect, useCallback, useRef } from \"react\";\nimport { useQuery } from \"@tanstack/react-query\";\nimport { useDataLayerCore } from \"./useDataLayer\";\nimport type { QueryOptions } from \"../core/types\";\nimport { devLog, devWarn } from \"../utils/dev-log\";\n\n// =============================================================================\n// Module Augmentation Interface\n// =============================================================================\n\n/**\n * Augment this interface in your app to enable automatic type inference.\n *\n * @example\n * // In types/db.d.ts\n * declare module \"@pol-studios/db\" {\n * interface DatabaseTypes {\n * database: import(\"@/database.types\").Database;\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface DatabaseTypes {}\n\n// =============================================================================\n// Database Type Helpers\n// =============================================================================\n\n/**\n * The configured Database type, or a generic fallback\n */\ntype ConfiguredDatabase = DatabaseTypes extends {\n database: infer DB;\n} ? DB : GenericSchema;\n\n/**\n * Generic schema structure for fallback\n */\ntype GenericSchema = {\n public: {\n Tables: Record<string, {\n Row: Record<string, unknown>;\n }>;\n Views: Record<string, {\n Row: Record<string, unknown>;\n }>;\n };\n [schema: string]: {\n Tables: Record<string, {\n Row: Record<string, unknown>;\n }>;\n Views?: Record<string, {\n Row: Record<string, unknown>;\n }>;\n };\n};\n\n/**\n * Default schema from Database (usually \"public\")\n */\ntype DefaultSchema = ConfiguredDatabase extends {\n public: infer S;\n} ? S : never;\n\n/**\n * Extract all valid table names from the default schema\n */\nexport type PublicTableNames = DefaultSchema extends {\n Tables: infer T;\n} ? keyof T & string : string;\n\n/**\n * Extract all valid schema names\n */\nexport type SchemaNames = keyof ConfiguredDatabase & string;\n\n/**\n * Extract table names for a specific schema\n */\nexport type SchemaTableNames<S extends string> = ConfiguredDatabase extends { [K in S]: {\n Tables: infer T;\n} } ? keyof T & string : string;\n\n/**\n * Build dot notation strings for all schema.table combinations\n */\ntype SchemaDotTable = { [S in SchemaNames]: S extends \"public\" ? never // Skip public schema for dot notation\n: `${S}.${SchemaTableNames<S>}` }[SchemaNames];\n\n/**\n * Table identifier - provides autocomplete for valid table names\n *\n * Supports:\n * - \"TableName\" - public schema tables\n * - \"schema.TableName\" - dot notation for other schemas\n * - { schema, table } - object format for other schemas\n */\nexport type TableIdentifier = PublicTableNames | SchemaDotTable | { [S in Exclude<SchemaNames, \"public\">]: {\n schema: S;\n table: SchemaTableNames<S>;\n} }[Exclude<SchemaNames, \"public\">];\n\n/**\n * Resolve row type from a table identifier\n *\n * Supports:\n * - \"TableName\" → public schema\n * - \"schema.TableName\" → specified schema (dot notation)\n * - { schema: \"schema\", table: \"TableName\" } → specified schema (object)\n */\nexport type ResolveRowType<T extends TableIdentifier> = T extends string ?\n// Check for dot notation first (e.g., \"core.Profile\")\nT extends `${infer Schema}.${infer Table}` ? ConfiguredDatabase extends { [K in Schema]: {\n Tables: { [K2 in Table]: {\n Row: infer R;\n } };\n} } ? R : Record<string, unknown> :\n// Plain string - look in public schema\nDefaultSchema extends {\n Tables: { [K in T]: {\n Row: infer R;\n } };\n} ? R : DefaultSchema extends {\n Views: { [K in T]: {\n Row: infer R;\n } };\n} ? R : Record<string, unknown> : T extends {\n schema: infer S;\n table: infer TN;\n} ?\n// Object with schema - look in specified schema\nS extends string ? TN extends string ? ConfiguredDatabase extends { [K in S]: {\n Tables: { [K2 in TN]: {\n Row: infer R;\n } };\n} } ? R : Record<string, unknown> : Record<string, unknown> : Record<string, unknown> : Record<string, unknown>;\n\n// =============================================================================\n// Types\n// =============================================================================\n\n/**\n * Options for useDbQuery hook\n */\nexport interface UseDbQueryOptions extends Omit<QueryOptions, \"enabled\"> {\n /** Whether the query is enabled (default: true) */\n enabled?: boolean;\n /**\n * React Query stale time in ms\n * Default depends on backend:\n * - PowerSync (offline): 0 - always refetch from SQLite (disk is fast)\n * - Supabase (online): 30000 - use normal caching\n */\n staleTime?: number;\n /** React Query gcTime (cache time) in ms (default: 300000 - 5 minutes) */\n gcTime?: number;\n /** Whether to refetch on window focus (default: true) */\n refetchOnWindowFocus?: boolean;\n /**\n * Whether to refetch on mount\n * Default depends on backend:\n * - PowerSync (offline): \"always\" - always query SQLite\n * - Supabase (online): true - refetch if stale\n */\n refetchOnMount?: boolean | \"always\";\n /** Whether to enable real-time subscriptions (if adapter supports) */\n realtime?: boolean;\n /** If true, returns single item instead of array (for compatibility with V2) */\n single?: boolean;\n}\n\n/**\n * Result from useDbQuery hook\n */\nexport interface UseDbQueryResult<T> {\n /** Query data */\n data: T[] | undefined;\n /** Whether query is loading (initial load) */\n isLoading: boolean;\n /** Whether query is in pending state */\n isPending: boolean;\n /** Whether query is currently fetching (including refetch) */\n isFetching: boolean;\n /** Whether query is currently refetching (alias for isFetching for V2 compatibility) */\n isRefetching: boolean;\n /** Whether query completed successfully */\n isSuccess: boolean;\n /** Whether query errored */\n isError: boolean;\n /** Query error if any */\n error: Error | null;\n /** Refetch the query */\n refetch: () => Promise<void>;\n /** Total count (if pagination is used) */\n count?: number;\n /** Whether data is stale */\n isStale: boolean;\n /** Timestamp of last data update */\n dataUpdatedAt: number | null;\n}\n\n// =============================================================================\n// Helper Functions\n// =============================================================================\n\n/**\n * Build a query key for React Query\n *\n * Creates a stable, unique key for caching based on table and query options.\n * Keys are namespaced with \"v3\" to avoid collisions with V2 queries.\n *\n * NOTE: Backend is intentionally NOT included in the key. The data is the same\n * regardless of whether it comes from Supabase or PowerSync - switching backends\n * should NOT invalidate the cache. This is critical for offline-first UX.\n */\nfunction buildQueryKey(table: string, options: UseDbQueryOptions): unknown[] {\n return [\"v3\", \"query\", table, options.select ?? \"*\", JSON.stringify(options.where ?? {}), JSON.stringify(options.orderBy ?? []), options.limit, options.offset];\n}\n\n/**\n * Serialize query options for dependency tracking\n */\nfunction serializeQueryOptions(options: UseDbQueryOptions): string {\n return JSON.stringify({\n select: options.select,\n where: options.where,\n orderBy: options.orderBy,\n limit: options.limit,\n offset: options.offset\n });\n}\n\n// =============================================================================\n// Hook Implementation\n// =============================================================================\n\n/**\n * Helper to resolve table name from TableIdentifier\n */\nfunction resolveTableName(table: TableIdentifier): string {\n if (typeof table === \"string\") {\n return table;\n }\n return `${table.schema}.${table.table}`;\n}\n\n/**\n * Hook for querying multiple records from a table\n *\n * This hook provides a unified interface for querying data that works\n * identically whether the backend is PowerSync (offline-first) or\n * Supabase (online-only). It uses React Query for caching and state management.\n *\n * Features:\n * - Automatic type inference from table names (when DatabaseTypes is augmented)\n * - Automatic backend selection based on DataLayerProvider configuration\n * - React Query integration for caching, deduplication, and background updates\n * - Optional real-time subscriptions (when adapter supports it)\n * - Pagination support with count\n *\n * @param table - Table name (string) or { schema, table } object\n * @param options - Query options (select, where, orderBy, limit, offset, etc.)\n * @returns Query result with data, loading states, error, and refetch function\n *\n * @example\n * // Basic query - types auto-inferred from table name\n * const { data } = useDbQuery(\"EquipmentFixtureUnit\");\n * // data is typed as Tables<\"EquipmentFixtureUnit\">[]\n *\n * @example\n * // Query from non-public schema\n * const { data } = useDbQuery({ schema: \"core\", table: \"Profile\" });\n * // data is typed as Tables<{ schema: \"core\" }, \"Profile\">[]\n *\n * @example\n * // Query with filters and sorting\n * const { data } = useDbQuery(\"Task\", {\n * select: \"*, Project(*)\",\n * where: { status: \"active\" },\n * orderBy: [{ field: \"createdAt\", direction: \"desc\" }],\n * limit: 10,\n * });\n */\n/**\n * Main hook signature with auto-inferred types from table identifiers\n */\nexport function useDbQuery<T extends TableIdentifier>(table: T, options?: UseDbQueryOptions): UseDbQueryResult<ResolveRowType<T>>;\n\n/**\n * Overload for explicit type parameter when table name is a string literal\n */\nexport function useDbQuery<T>(table: string, options?: UseDbQueryOptions): UseDbQueryResult<T>;\n\n// Implementation signature - uses any to satisfy both overloads\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useDbQuery<T = any>(table: TableIdentifier | string, options: UseDbQueryOptions = {}): UseDbQueryResult<T> {\n const tableName = typeof table === \"string\" ? table : resolveTableName(table as TableIdentifier);\n const {\n registry,\n queryClient,\n powerSync\n } = useDataLayerCore();\n\n // Determine if using PowerSync (offline/SQLite) or Supabase (online)\n const isPowerSync = powerSync !== null;\n\n // Backend-aware defaults:\n // - PowerSync: staleTime=0, refetchOnMount=\"always\" (SQLite is fast, always query disk)\n // - Supabase: staleTime=30000, refetchOnMount=true (use normal React Query caching)\n // - realtime: PowerSync=true (use watch() for live updates), Supabase=false (no streaming)\n const {\n enabled = true,\n staleTime = isPowerSync ? 0 : 30000,\n gcTime = 300000,\n // 5 minutes - keep in memory for instant display while refetching\n refetchOnWindowFocus = true,\n refetchOnMount = isPowerSync ? \"always\" : true,\n realtime = isPowerSync,\n // Enable real-time subscriptions by default for PowerSync\n ...queryOptions\n } = options;\n\n // Get adapter for this table\n // No isInitialized check needed - if we get here, core context exists = initialized\n const adapter = useMemo(() => {\n try {\n return registry.getAdapter(tableName);\n } catch {\n return null;\n }\n }, [registry, tableName]);\n\n // Serialize options into a stable memoized value BEFORE using in other dependencies\n const serializedOptions = useMemo(() => serializeQueryOptions(options), [options.select, options.where, options.orderBy, options.limit, options.offset]);\n\n // Build query key - memoized to prevent unnecessary re-renders\n // Backend is NOT included - cache persists across backend switches for offline-first UX\n const queryKey = useMemo(() => buildQueryKey(tableName, options), [tableName, serializedOptions]);\n\n // Memoize query options to prevent re-creating on every render\n const memoizedQueryOptions = useMemo(() => ({\n select: queryOptions.select,\n where: queryOptions.where,\n orderBy: queryOptions.orderBy,\n limit: queryOptions.limit,\n offset: queryOptions.offset\n }), [serializedOptions]);\n\n // Query function - resolve adapter lazily at query time to ensure we always\n // have the latest adapter instance (the memoized adapter may be stale)\n const queryFn = useCallback(async () => {\n // Use currentAdapter directly - registry.getAdapter() throws if unavailable\n const currentAdapter = registry.getAdapter(tableName);\n const result = await currentAdapter.query(tableName, memoizedQueryOptions);\n return result;\n }, [registry, tableName, memoizedQueryOptions]);\n\n // Execute query with React Query\n // Backend-aware caching strategy:\n // - PowerSync: SQLite is source of truth, always refetch from disk (it's fast)\n // - Supabase: Use normal React Query caching to avoid unnecessary network requests\n const query = useQuery({\n queryKey,\n queryFn,\n enabled: enabled && adapter !== null,\n staleTime,\n gcTime,\n refetchOnWindowFocus,\n refetchOnMount\n });\n\n // Create debounced invalidation function for subscriptions\n const invalidateTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const debouncedInvalidate = useCallback(() => {\n if (invalidateTimeoutRef.current) {\n clearTimeout(invalidateTimeoutRef.current);\n }\n invalidateTimeoutRef.current = setTimeout(() => {\n queryClient.invalidateQueries({\n queryKey\n });\n }, 100);\n }, [queryClient, queryKey]);\n\n // Clean up timeout on unmount\n useEffect(() => {\n return () => {\n if (invalidateTimeoutRef.current) {\n clearTimeout(invalidateTimeoutRef.current);\n }\n };\n }, []);\n\n // Set up real-time subscription if enabled\n useEffect(() => {\n // Resolve adapter lazily to get current backend\n let currentAdapter_0;\n try {\n currentAdapter_0 = registry.getAdapter(tableName);\n } catch {\n return; // Adapter not available yet\n }\n if (!realtime || !currentAdapter_0?.subscribe) {\n return;\n }\n\n // Only skip first callback for PowerSync adapter (which fires immediately with current data)\n // SupabaseAdapter's subscribe only fires on actual database changes\n // Use currentAdapter.name for the isFirstCallback check (survives minification)\n const isPowerSyncAdapter = currentAdapter_0.name === \"powersync\";\n let isFirstCallback = isPowerSyncAdapter;\n const unsubscribe = currentAdapter_0.subscribe(tableName, memoizedQueryOptions, data => {\n // Skip the first callback since initial query handles it\n if (isFirstCallback) {\n isFirstCallback = false;\n return;\n }\n\n // Check if query has relations (contains parentheses like \"Table(*)\")\n const hasRelations = memoizedQueryOptions.select?.includes(\"(\");\n if (hasRelations) {\n // Has relations - use debounced invalidation to prevent rapid successive invalidations\n debouncedInvalidate();\n } else {\n // No relations - safe to directly update cache with flat data\n queryClient.setQueryData(queryKey, {\n data,\n count: data.length\n });\n }\n });\n return () => {\n unsubscribe?.();\n };\n }, [realtime, registry, tableName, memoizedQueryOptions, queryClient, queryKey, debouncedInvalidate]);\n\n // Dev logging for debugging\n useEffect(() => {\n const adapterName = adapter?.name ?? \"unknown\";\n\n // Log errors\n if (query.isError && query.error) {\n devWarn(\"useDbQuery\", `${tableName} via ${adapterName}: Error - ${query.error.message}`);\n }\n\n // Log empty results (only after successful fetch, not during loading)\n if (query.isSuccess && query.data?.data?.length === 0) {\n devLog(\"useDbQuery\", `${tableName} via ${adapterName}: 0 results`);\n }\n }, [query.isError, query.error, query.isSuccess, query.data, tableName, adapter]);\n\n // Build refetch function\n const refetch = useCallback(async () => {\n await query.refetch();\n }, [query]);\n return {\n data: query.data?.data as T[] | undefined,\n isLoading: query.isLoading,\n isPending: query.isPending,\n isFetching: query.isFetching,\n isRefetching: query.isFetching,\n // Alias for V2 compatibility\n isSuccess: query.isSuccess,\n isError: query.isError,\n error: query.error as Error | null,\n refetch,\n count: query.data?.count,\n isStale: query.isStale,\n dataUpdatedAt: query.dataUpdatedAt ?? null\n };\n}\nexport default useDbQuery;","/**\n * Development-only logging utility for V3 hooks\n *\n * Logs are only output when __DEV__ is true (development builds).\n * In production builds, these calls are no-ops.\n */\n\ndeclare const __DEV__: boolean;\n\n/**\n * Log a message with a prefix, only in development\n *\n * @param prefix - Hook or component name (e.g., \"useDbQuery\")\n * @param message - Message to log\n *\n * @example\n * devLog(\"useDbQuery\", \"EquipmentUnit via PowerSync: 0 results\");\n * // Output: [useDbQuery] EquipmentUnit via PowerSync: 0 results\n */\nexport function devLog(prefix: string, message: string): void {\n if (typeof __DEV__ !== \"undefined\" && __DEV__) {\n console.log(`[${prefix}] ${message}`);\n }\n}\n\n/**\n * Log a warning with a prefix, only in development\n */\nexport function devWarn(prefix: string, message: string): void {\n if (typeof __DEV__ !== \"undefined\" && __DEV__) {\n console.warn(`[${prefix}] ${message}`);\n }\n}\n\n/**\n * Log an error with a prefix, only in development\n */\nexport function devError(prefix: string, message: string, error?: unknown): void {\n if (typeof __DEV__ !== \"undefined\" && __DEV__) {\n if (error) {\n console.error(`[${prefix}] ${message}`, error);\n } else {\n console.error(`[${prefix}] ${message}`);\n }\n }\n}"],"mappings":";AAcA,SAAS,qBAAqB;AA0HvB,IAAM,uBAAuB,cAAgD,IAAI;AACxF,qBAAqB,cAAc;AAQ5B,IAAM,yBAAyB,cAAkD,IAAI;AAC5F,uBAAuB,cAAc;AAS9B,IAAM,mBAAmB,cAA4C,IAAI;AAChF,iBAAiB,cAAc;;;AC5I/B,SAAS,kBAAkB;AA4BpB,SAAS,mBAAmB;AACjC,QAAM,UAAU,WAAW,oBAAoB;AAC/C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,yHAAyH;AAAA,EAC3I;AACA,SAAO;AACT;AAeO,SAAS,2BAA2B;AACzC,SAAO,WAAW,oBAAoB;AACxC;AA0BO,SAAS,qBAAqB;AACnC,QAAM,UAAU,WAAW,sBAAsB;AACjD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,2HAA2H;AAAA,EAC7I;AACA,SAAO;AACT;AAiCO,SAAS,eAAe;AAC7B,QAAM,UAAU,WAAW,gBAAgB;AAC3C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,qHAAqH;AAAA,EACvI;AACA,SAAO;AACT;AAkBO,SAAS,uBAAuB;AACrC,SAAO,WAAW,gBAAgB;AACpC;;;ACvIA,SAAS,SAAS,WAAW,aAAa,cAAc;AACxD,SAAS,gBAAgB;;;ACLlB,SAAS,OAAO,QAAgB,SAAuB;AAC5D,MAAI,OAAO,YAAY,eAAe,SAAS;AAC7C,YAAQ,IAAI,IAAI,MAAM,KAAK,OAAO,EAAE;AAAA,EACtC;AACF;AAKO,SAAS,QAAQ,QAAgB,SAAuB;AAC7D,MAAI,OAAO,YAAY,eAAe,SAAS;AAC7C,YAAQ,KA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