@pol-studios/db 1.0.12 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/{DataLayerContext-CL6alnkb.d.ts → DataLayerContext-Cm1nAvT7.d.ts} +55 -3
  2. package/dist/auth/context.js +2 -2
  3. package/dist/auth/hooks.js +3 -3
  4. package/dist/auth/index.js +3 -3
  5. package/dist/{chunk-XU3SBFAG.js → chunk-467E52YA.js} +40 -7
  6. package/dist/chunk-467E52YA.js.map +1 -0
  7. package/dist/{chunk-NZON56CB.js → chunk-7OQKP7EP.js} +3 -3
  8. package/dist/{chunk-ZVBHWU7O.js → chunk-CBLXKHSK.js} +83 -26
  9. package/dist/chunk-CBLXKHSK.js.map +1 -0
  10. package/dist/{chunk-LNJ3WF7V.js → chunk-NSVDEHEI.js} +4 -4
  11. package/dist/{chunk-WGDJ4IXR.js → chunk-O4P43BD7.js} +2 -2
  12. package/dist/{chunk-DJ6VLEAL.js → chunk-WLHUPDBI.js} +2 -2
  13. package/dist/hooks/index.d.ts +12 -2
  14. package/dist/hooks/index.js +5 -1
  15. package/dist/{index-CQLyNG6A.d.ts → index-BHFInYVr.d.ts} +1 -1
  16. package/dist/index.d.ts +4 -4
  17. package/dist/index.js +14 -6
  18. package/dist/index.native.d.ts +5 -5
  19. package/dist/index.native.js +10 -6
  20. package/dist/index.web.d.ts +5 -5
  21. package/dist/index.web.js +5 -5
  22. package/dist/types/index.d.ts +2 -2
  23. package/dist/{useDbCount-BG356T9i.d.ts → useDbCount-Cu2Q5ZdH.d.ts} +64 -6
  24. package/dist/{useResolveFeedback-BWmatBlE.d.ts → useResolveFeedback-Bg3JDRs8.d.ts} +3 -3
  25. package/dist/with-auth/index.js +4 -4
  26. package/package.json +1 -1
  27. package/dist/chunk-XU3SBFAG.js.map +0 -1
  28. package/dist/chunk-ZVBHWU7O.js.map +0 -1
  29. /package/dist/{chunk-NZON56CB.js.map → chunk-7OQKP7EP.js.map} +0 -0
  30. /package/dist/{chunk-LNJ3WF7V.js.map → chunk-NSVDEHEI.js.map} +0 -0
  31. /package/dist/{chunk-WGDJ4IXR.js.map → chunk-O4P43BD7.js.map} +0 -0
  32. /package/dist/{chunk-DJ6VLEAL.js.map → chunk-WLHUPDBI.js.map} +0 -0
@@ -722,7 +722,44 @@ interface DataLayerStatus {
722
722
  hasSynced: boolean;
723
723
  }
724
724
  /**
725
- * Context value for the data layer
725
+ * STABLE core context - values that don't change after initialization
726
+ *
727
+ * Use useDataLayerCore() to access these values in query/mutation hooks
728
+ * to avoid re-renders when sync status changes.
729
+ */
730
+ interface DataLayerCoreContextValue {
731
+ /** Adapter registry for getting table adapters */
732
+ registry: AdapterRegistry;
733
+ /** Get adapter for a specific table */
734
+ getAdapter: (table: string) => TableDataAdapter;
735
+ /** PowerSync database instance (null when not available) */
736
+ powerSync: PowerSyncDatabase | null;
737
+ /** Supabase client (always available) */
738
+ supabase: SupabaseClient;
739
+ /** React Query client */
740
+ queryClient: QueryClient;
741
+ /** Database schema */
742
+ schema: DatabaseSchema;
743
+ }
744
+ /**
745
+ * DYNAMIC status context - values that change during runtime
746
+ *
747
+ * Use useDataLayerStatus() for UI components that display sync status,
748
+ * online indicator, etc. Components using this WILL re-render when status changes.
749
+ */
750
+ interface DataLayerStatusContextValue {
751
+ /** Current status */
752
+ status: DataLayerStatus;
753
+ /** Sync status (for PowerSync, no-op for Supabase-only) */
754
+ syncStatus: SyncStatus;
755
+ /** Sync controls (for PowerSync, no-op for Supabase-only) */
756
+ syncControl: SyncControl;
757
+ }
758
+ /**
759
+ * Context value for the data layer (combines core and status)
760
+ *
761
+ * @deprecated Prefer using useDataLayerCore() or useDataLayerStatus() for better performance.
762
+ * This combined interface is kept for backward compatibility.
726
763
  */
727
764
  interface DataLayerContextValue {
728
765
  /** Adapter registry for getting table adapters */
@@ -745,11 +782,26 @@ interface DataLayerContextValue {
745
782
  syncControl: SyncControl;
746
783
  }
747
784
  /**
748
- * Data layer context
785
+ * STABLE Core context - values that don't change after initialization
786
+ *
787
+ * Use useDataLayerCore() hook to access. Components consuming this context
788
+ * will NOT re-render when sync status or network status changes.
789
+ */
790
+ declare const DataLayerCoreContext: react.Context<DataLayerCoreContextValue>;
791
+ /**
792
+ * DYNAMIC Status context - values that change during runtime
793
+ *
794
+ * Use useDataLayerStatus() hook to access. Components consuming this context
795
+ * WILL re-render when sync status or network status changes.
796
+ */
797
+ declare const DataLayerStatusContext: react.Context<DataLayerStatusContextValue>;
798
+ /**
799
+ * Combined data layer context (backward compatibility)
749
800
  *
801
+ * @deprecated Prefer using DataLayerCoreContext or DataLayerStatusContext for better performance.
750
802
  * Provides access to the V3 data layer throughout the React component tree.
751
803
  * Must be accessed via the useDataLayer hook or similar consumer.
752
804
  */
753
805
  declare const DataLayerContext: react.Context<DataLayerContextValue>;
754
806
 
755
- export { type AdapterQueryResult as A, BackendStatus as B, type CapableDataAdapter as C, DataLayerContext as D, type SyncStatusInfo as S, type TableDataAdapter as T, type AdapterConfig as a, type AdapterFactory as b, type AdapterCapabilities as c, type AdapterDependencies as d, type AdapterStrategyType as e, ADAPTER_STRATEGIES as f, AdapterRegistry as g, createAdapterRegistry as h, AdapterAutoDetector as i, createAdapterAutoDetector as j, type AutoDetectionResult as k, type AutoDetectorOptions as l, type BackendChangeListener as m, type DataLayerContextValue as n, type DataLayerStatus as o };
807
+ export { type AdapterQueryResult as A, BackendStatus as B, type CapableDataAdapter as C, DataLayerContext as D, type SyncStatusInfo as S, type TableDataAdapter as T, type AdapterConfig as a, type AdapterFactory as b, type AdapterCapabilities as c, type AdapterDependencies as d, type AdapterStrategyType as e, ADAPTER_STRATEGIES as f, AdapterRegistry as g, createAdapterRegistry as h, AdapterAutoDetector as i, createAdapterAutoDetector as j, type AutoDetectionResult as k, type AutoDetectorOptions as l, type BackendChangeListener as m, DataLayerCoreContext as n, DataLayerStatusContext as o, type DataLayerContextValue as p, type DataLayerCoreContextValue as q, type DataLayerStatusContextValue as r, type DataLayerStatus as s };
@@ -12,8 +12,8 @@ import {
12
12
  useUserMetadataState,
13
13
  useUserMetadataValue,
14
14
  userMetadataContext
15
- } from "../chunk-WGDJ4IXR.js";
16
- import "../chunk-ZVBHWU7O.js";
15
+ } from "../chunk-O4P43BD7.js";
16
+ import "../chunk-CBLXKHSK.js";
17
17
  import "../chunk-GC3TBUWE.js";
18
18
  import "../chunk-J4ZVCXZ4.js";
19
19
  import "../chunk-OQ7U6EQ3.js";
@@ -11,14 +11,14 @@ import {
11
11
  usePermissionLoading,
12
12
  usePermissionsBatch,
13
13
  useSetupAuth
14
- } from "../chunk-DJ6VLEAL.js";
14
+ } from "../chunk-WLHUPDBI.js";
15
15
  import {
16
16
  useSetUserMetadata,
17
17
  useUserMetadata,
18
18
  useUserMetadataState,
19
19
  useUserMetadataValue
20
- } from "../chunk-WGDJ4IXR.js";
21
- import "../chunk-ZVBHWU7O.js";
20
+ } from "../chunk-O4P43BD7.js";
21
+ import "../chunk-CBLXKHSK.js";
22
22
  import "../chunk-GC3TBUWE.js";
23
23
  import "../chunk-J4ZVCXZ4.js";
24
24
  import "../chunk-OQ7U6EQ3.js";
@@ -12,7 +12,7 @@ import {
12
12
  usePermissionLoading,
13
13
  usePermissionsBatch,
14
14
  useSetupAuth
15
- } from "../chunk-DJ6VLEAL.js";
15
+ } from "../chunk-WLHUPDBI.js";
16
16
  import {
17
17
  AuthProvider,
18
18
  PermissionProvider,
@@ -27,8 +27,8 @@ import {
27
27
  useUserMetadataState,
28
28
  useUserMetadataValue,
29
29
  userMetadataContext
30
- } from "../chunk-WGDJ4IXR.js";
31
- import "../chunk-ZVBHWU7O.js";
30
+ } from "../chunk-O4P43BD7.js";
31
+ import "../chunk-CBLXKHSK.js";
32
32
  import {
33
33
  hasAccess,
34
34
  hasAllAccess,
@@ -2,10 +2,12 @@ import {
2
2
  createAdapterAutoDetector,
3
3
  createAdapterRegistry,
4
4
  createSupabaseAdapter
5
- } from "./chunk-NZON56CB.js";
5
+ } from "./chunk-7OQKP7EP.js";
6
6
  import {
7
- DataLayerContext
8
- } from "./chunk-ZVBHWU7O.js";
7
+ DataLayerContext,
8
+ DataLayerCoreContext,
9
+ DataLayerStatusContext
10
+ } from "./chunk-CBLXKHSK.js";
9
11
  import {
10
12
  QueryExecutor,
11
13
  extractRelationNames,
@@ -1644,6 +1646,7 @@ function DataLayerProvider({
1644
1646
  powerSyncSyncStatus
1645
1647
  }) {
1646
1648
  const [registry] = useState(() => createAdapterRegistry(config));
1649
+ const [isInitializedOnce, setIsInitializedOnce] = useState(false);
1647
1650
  const [autoDetector, setAutoDetector] = useState(null);
1648
1651
  const [status, setStatus] = useState({
1649
1652
  isInitialized: false,
@@ -1773,6 +1776,11 @@ function DataLayerProvider({
1773
1776
  }
1774
1777
  }
1775
1778
  }, [status.isInitialized, status.error]);
1779
+ useEffect(() => {
1780
+ if (status.isInitialized && !isInitializedOnce) {
1781
+ setIsInitializedOnce(true);
1782
+ }
1783
+ }, [status.isInitialized, isInitializedOnce]);
1776
1784
  const getAdapter = useCallback((table) => {
1777
1785
  return registry.getAdapter(table);
1778
1786
  }, [registry]);
@@ -1790,16 +1798,41 @@ function DataLayerProvider({
1790
1798
  syncControl: defaultSyncControl
1791
1799
  };
1792
1800
  }, [registry, getAdapter, powerSyncInstance, supabaseClient, queryClient, config.schema, status]);
1793
- const contextValue = useMemo(() => buildContextValue(), [buildContextValue]);
1801
+ const coreContextValue = useMemo(() => {
1802
+ if (!isInitializedOnce) return null;
1803
+ return {
1804
+ registry,
1805
+ getAdapter,
1806
+ powerSync: powerSyncInstance,
1807
+ supabase: supabaseClient,
1808
+ queryClient,
1809
+ schema: config.schema
1810
+ };
1811
+ }, [isInitializedOnce, registry, getAdapter, powerSyncInstance, supabaseClient, queryClient, config.schema]);
1812
+ const statusContextValue = useMemo(() => {
1813
+ if (!status.isInitialized) return null;
1814
+ return {
1815
+ status,
1816
+ syncStatus: defaultSyncStatus,
1817
+ syncControl: defaultSyncControl
1818
+ };
1819
+ }, [status]);
1820
+ const contextValue = useMemo(() => {
1821
+ if (!coreContextValue || !statusContextValue) return null;
1822
+ return {
1823
+ ...coreContextValue,
1824
+ ...statusContextValue
1825
+ };
1826
+ }, [coreContextValue, statusContextValue]);
1794
1827
  useEffect(() => {
1795
1828
  return () => {
1796
1829
  registry.dispose();
1797
1830
  };
1798
1831
  }, [registry]);
1799
- if (!contextValue) {
1832
+ if (!contextValue || !coreContextValue || !statusContextValue) {
1800
1833
  return null;
1801
1834
  }
1802
- return /* @__PURE__ */ jsx(DataLayerContext.Provider, { value: contextValue, children });
1835
+ return /* @__PURE__ */ jsx(DataLayerCoreContext.Provider, { value: coreContextValue, children: /* @__PURE__ */ jsx(DataLayerStatusContext.Provider, { value: statusContextValue, children: /* @__PURE__ */ jsx(DataLayerContext.Provider, { value: contextValue, children }) }) });
1803
1836
  }
1804
1837
 
1805
1838
  // src/storage/use-supabase-upload.tsx
@@ -5202,4 +5235,4 @@ object-assign/index.js:
5202
5235
  @license MIT
5203
5236
  *)
5204
5237
  */
5205
- //# sourceMappingURL=chunk-XU3SBFAG.js.map
5238
+ //# sourceMappingURL=chunk-467E52YA.js.map