@pol-studios/db 1.0.48 → 1.0.49

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.
@@ -292,6 +292,13 @@ declare class AdapterAutoDetector {
292
292
  private lastResult;
293
293
  private syncStatus;
294
294
  constructor(powerSyncDb: PowerSyncDatabase | null, supabase: SupabaseClient | null, options?: AutoDetectorOptions);
295
+ /**
296
+ * Update the PowerSync database reference.
297
+ * Called when PowerSync becomes available after initial construction.
298
+ *
299
+ * @param db - PowerSync database instance or null
300
+ */
301
+ setPowerSyncDb(db: PowerSyncDatabase | null): void;
295
302
  /**
296
303
  * Update the sync status from PowerSync.
297
304
  * Called when sync status changes to re-evaluate backend recommendation.
@@ -530,9 +537,19 @@ declare class AdapterRegistry {
530
537
  */
531
538
  private adapters;
532
539
  /**
533
- * PowerSync adapter instance (set during initialization)
540
+ * PowerSync adapter instance (set during initialization or lazily via getter)
534
541
  */
535
542
  private powerSyncAdapter;
543
+ /**
544
+ * Getter function to retrieve PowerSync database instance.
545
+ * Used for lazy initialization when PowerSync becomes available after registry creation.
546
+ */
547
+ private powerSyncGetter;
548
+ /**
549
+ * Factory function to create PowerSync adapter from database instance.
550
+ * Set via setPowerSyncGetter along with the getter.
551
+ */
552
+ private powerSyncAdapterFactory;
536
553
  /**
537
554
  * Supabase adapter instance (set during initialization)
538
555
  */
@@ -592,6 +609,26 @@ declare class AdapterRegistry {
592
609
  * @param adapter - PowerSync adapter implementation
593
610
  */
594
611
  setPowerSyncAdapter(adapter: TableDataAdapter): void;
612
+ /**
613
+ * Set a getter function for lazy PowerSync adapter initialization.
614
+ *
615
+ * This allows the registry to lazily create the PowerSync adapter when
616
+ * PowerSync becomes available, rather than requiring it at initialization time.
617
+ * Solves race conditions where queries/mutations run before PowerSync is ready.
618
+ *
619
+ * @param getter - Function that returns the PowerSync database instance (or null if not ready)
620
+ * @param factory - Function that creates a TableDataAdapter from the database instance
621
+ */
622
+ setPowerSyncGetter(getter: () => unknown, factory: (db: unknown) => TableDataAdapter): void;
623
+ /**
624
+ * Ensure PowerSync adapter is initialized if available.
625
+ *
626
+ * Checks the getter (if set) and lazily creates the adapter if PowerSync
627
+ * is now available. Also updates the auto-detector with the new reference.
628
+ *
629
+ * @returns true if PowerSync adapter is available, false otherwise
630
+ */
631
+ private ensurePowerSyncAdapter;
595
632
  /**
596
633
  * Set the sync tracker for mutation tracking.
597
634
  * When set, write operations on PowerSync tables will
@@ -643,7 +680,7 @@ declare class AdapterRegistry {
643
680
  * @returns The appropriate adapter for the table
644
681
  * @throws Error if adapters are not initialized
645
682
  */
646
- getAdapter(table: string, operation?: 'read' | 'write'): TableDataAdapter;
683
+ getAdapter(table: string, _operation?: 'read' | 'write'): TableDataAdapter;
647
684
  /**
648
685
  * Get the PowerSync adapter directly
649
686
  *
@@ -3,7 +3,7 @@ import {
3
3
  createAdapterRegistry,
4
4
  createSupabaseAdapter,
5
5
  stripSchemaPrefix
6
- } from "./chunk-GEU5ED7L.js";
6
+ } from "./chunk-V4MNSMMA.js";
7
7
  import {
8
8
  DataLayerContext,
9
9
  DataLayerCoreContext,
@@ -1407,7 +1407,7 @@ function createPowerSyncAdapter(db, schema) {
1407
1407
  }
1408
1408
 
1409
1409
  // src/providers/DataLayerProvider.tsx
1410
- import { useState, useEffect, useMemo, useCallback } from "react";
1410
+ import { useState, useEffect, useMemo, useCallback, useRef } from "react";
1411
1411
  import { jsx } from "react/jsx-runtime";
1412
1412
  var defaultSyncStatus = {
1413
1413
  isConnected: false,
@@ -1455,6 +1455,8 @@ function DataLayerProvider({
1455
1455
  syncControl: externalSyncControl
1456
1456
  }) {
1457
1457
  const [registry] = useState(() => createAdapterRegistry(config));
1458
+ const powerSyncInstanceRef = useRef(powerSyncInstance);
1459
+ powerSyncInstanceRef.current = powerSyncInstance;
1458
1460
  const resolvedSyncControl = useMemo(() => externalSyncControl ?? defaultSyncControl, [externalSyncControl]);
1459
1461
  const [isInitializedOnce, setIsInitializedOnce] = useState(false);
1460
1462
  const [autoDetector, setAutoDetector] = useState(null);
@@ -1476,6 +1478,7 @@ function DataLayerProvider({
1476
1478
  setAutoDetector(detector);
1477
1479
  const supabaseAdapter = createSupabaseAdapter(supabaseClient, config.schema);
1478
1480
  registry.setSupabaseAdapter(supabaseAdapter);
1481
+ registry.setPowerSyncGetter(() => powerSyncInstanceRef.current, (db) => createPowerSyncAdapter(db, config.schema));
1479
1482
  if (powerSyncInstance) {
1480
1483
  const powerSyncAdapter = createPowerSyncAdapter(powerSyncInstance, config.schema);
1481
1484
  registry.setPowerSyncAdapter(powerSyncAdapter);
@@ -1691,7 +1694,7 @@ import { useCallback as useCallback3, useEffect as useEffect3, useMemo as useMem
1691
1694
 
1692
1695
  // ../../../node_modules/.pnpm/react-dropzone@14.3.8_react@19.2.0/node_modules/react-dropzone/dist/es/index.js
1693
1696
  var import_prop_types = __toESM(require_prop_types(), 1);
1694
- import React2, { forwardRef, Fragment, useCallback as useCallback2, useEffect as useEffect2, useImperativeHandle, useMemo as useMemo2, useReducer, useRef } from "react";
1697
+ import React2, { forwardRef, Fragment, useCallback as useCallback2, useEffect as useEffect2, useImperativeHandle, useMemo as useMemo2, useReducer, useRef as useRef2 } from "react";
1695
1698
 
1696
1699
  // ../../../node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.mjs
1697
1700
  function __awaiter(thisArg, _arguments, P, generator) {
@@ -3707,11 +3710,11 @@ function useDropzone() {
3707
3710
  var onFileDialogCancelCb = useMemo2(function() {
3708
3711
  return typeof onFileDialogCancel === "function" ? onFileDialogCancel : noop;
3709
3712
  }, [onFileDialogCancel]);
3710
- var rootRef = useRef(null);
3711
- var inputRef = useRef(null);
3713
+ var rootRef = useRef2(null);
3714
+ var inputRef = useRef2(null);
3712
3715
  var _useReducer = useReducer(reducer, initialState), _useReducer2 = _slicedToArray2(_useReducer, 2), state = _useReducer2[0], dispatch = _useReducer2[1];
3713
3716
  var isFocused = state.isFocused, isFileDialogActive = state.isFileDialogActive;
3714
- var fsAccessApiWorksRef = useRef(typeof window !== "undefined" && window.isSecureContext && useFsAccessApi && canUseFileSystemAccessAPI());
3717
+ var fsAccessApiWorksRef = useRef2(typeof window !== "undefined" && window.isSecureContext && useFsAccessApi && canUseFileSystemAccessAPI());
3715
3718
  var onWindowFocus = function onWindowFocus2() {
3716
3719
  if (!fsAccessApiWorksRef.current && isFileDialogActive) {
3717
3720
  setTimeout(function() {
@@ -3733,7 +3736,7 @@ function useDropzone() {
3733
3736
  window.removeEventListener("focus", onWindowFocus, false);
3734
3737
  };
3735
3738
  }, [inputRef, isFileDialogActive, onFileDialogCancelCb, fsAccessApiWorksRef]);
3736
- var dragTargetsRef = useRef([]);
3739
+ var dragTargetsRef = useRef2([]);
3737
3740
  var onDocumentDrop = function onDocumentDrop2(event) {
3738
3741
  if (rootRef.current && rootRef.current.contains(event.target)) {
3739
3742
  return;
@@ -4212,7 +4215,7 @@ var useSupabaseUpload = (options) => {
4212
4215
 
4213
4216
  // src/conflicts/ConflictContext.tsx
4214
4217
  import { c as _c } from "react/compiler-runtime";
4215
- import { createContext, useEffect as useEffect4, useReducer as useReducer2, useRef as useRef2 } from "react";
4218
+ import { createContext, useEffect as useEffect4, useReducer as useReducer2, useRef as useRef3 } from "react";
4216
4219
 
4217
4220
  // src/conflicts/storage.ts
4218
4221
  import AsyncStorage from "@react-native-async-storage/async-storage";
@@ -4369,7 +4372,7 @@ function ConflictProvider(t0) {
4369
4372
  conflictBus
4370
4373
  } = t0;
4371
4374
  const [state, dispatch] = useReducer2(conflictReducer, initialState2);
4372
- const hasFinishedLoadingRef = useRef2(false);
4375
+ const hasFinishedLoadingRef = useRef3(false);
4373
4376
  let t1;
4374
4377
  if ($[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
4375
4378
  t1 = /* @__PURE__ */ new Map();
@@ -4377,7 +4380,7 @@ function ConflictProvider(t0) {
4377
4380
  } else {
4378
4381
  t1 = $[0];
4379
4382
  }
4380
- const savedAtTimestampsRef = useRef2(t1);
4383
+ const savedAtTimestampsRef = useRef3(t1);
4381
4384
  let t2;
4382
4385
  let t3;
4383
4386
  if ($[1] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
@@ -4952,4 +4955,4 @@ object-assign/index.js:
4952
4955
  @license MIT
4953
4956
  *)
4954
4957
  */
4955
- //# sourceMappingURL=chunk-WZOQ5KG2.js.map
4958
+ //# sourceMappingURL=chunk-GAJHPZ6N.js.map