@pol-studios/db 1.0.58 → 1.0.61

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 (52) hide show
  1. package/dist/DataLayerContext-V5FotiSk.d.ts +563 -0
  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-YRIPM2AN.js → chunk-4PZ744G2.js} +207 -6
  6. package/dist/chunk-4PZ744G2.js.map +1 -0
  7. package/dist/{chunk-OK2C54B6.js → chunk-7PBTPCRN.js} +340 -386
  8. package/dist/chunk-7PBTPCRN.js.map +1 -0
  9. package/dist/{chunk-6SDH7M7J.js → chunk-ARALLEDJ.js} +2 -2
  10. package/dist/{chunk-Z456IHCB.js → chunk-F4HW4NT5.js} +1 -1
  11. package/dist/chunk-F4HW4NT5.js.map +1 -0
  12. package/dist/{chunk-LG3OHLGB.js → chunk-FWCHS5NN.js} +16 -337
  13. package/dist/chunk-FWCHS5NN.js.map +1 -0
  14. package/dist/{chunk-4EO55YV2.js → chunk-H4Z73DC4.js} +4 -4
  15. package/dist/{chunk-GWYTROSD.js → chunk-L4DFVMTS.js} +335 -4
  16. package/dist/chunk-L4DFVMTS.js.map +1 -0
  17. package/dist/{chunk-7BGDQT5X.js → chunk-PIPB3JMK.js} +1 -7
  18. package/dist/{chunk-7BGDQT5X.js.map → chunk-PIPB3JMK.js.map} +1 -1
  19. package/dist/{chunk-MEBT5YHA.js → chunk-SNPZMRBC.js} +2 -2
  20. package/dist/{chunk-VYFAMTHI.js → chunk-ZPFZ2ZRW.js} +4 -13
  21. package/dist/{chunk-VYFAMTHI.js.map → chunk-ZPFZ2ZRW.js.map} +1 -1
  22. package/dist/core/index.d.ts +8 -44
  23. package/dist/{executor-D15yjeMo.d.ts → executor-Bu1OlqCl.d.ts} +43 -3
  24. package/dist/hooks/index.d.ts +3 -3
  25. package/dist/hooks/index.js +2 -2
  26. package/dist/{index-CFUuTzXO.d.ts → index-vwVJ0BWj.d.ts} +1 -9
  27. package/dist/index.d.ts +5 -5
  28. package/dist/index.js +21 -13
  29. package/dist/index.native.d.ts +77 -76
  30. package/dist/index.native.js +20 -12
  31. package/dist/index.web.d.ts +21 -44
  32. package/dist/index.web.js +215 -156
  33. package/dist/index.web.js.map +1 -1
  34. package/dist/powersync-bridge/index.d.ts +1 -1
  35. package/dist/powersync-bridge/index.js +1 -1
  36. package/dist/query/index.d.ts +1 -1
  37. package/dist/query/index.js +1 -1
  38. package/dist/types/index.d.ts +3 -3
  39. package/dist/types/index.js +1 -1
  40. package/dist/{useDbCount-Ckb-FhZk.d.ts → useDbCount-dCkdaBpP.d.ts} +41 -83
  41. package/dist/{useResolveFeedback-CuUkdHoR.d.ts → useResolveFeedback-thFi-4h8.d.ts} +429 -5
  42. package/dist/with-auth/index.js +5 -5
  43. package/package.json +1 -1
  44. package/dist/DataLayerContext-BYZtDD0g.d.ts +0 -946
  45. package/dist/chunk-GWYTROSD.js.map +0 -1
  46. package/dist/chunk-LG3OHLGB.js.map +0 -1
  47. package/dist/chunk-OK2C54B6.js.map +0 -1
  48. package/dist/chunk-YRIPM2AN.js.map +0 -1
  49. package/dist/chunk-Z456IHCB.js.map +0 -1
  50. /package/dist/{chunk-6SDH7M7J.js.map → chunk-ARALLEDJ.js.map} +0 -0
  51. /package/dist/{chunk-4EO55YV2.js.map → chunk-H4Z73DC4.js.map} +0 -0
  52. /package/dist/{chunk-MEBT5YHA.js.map → chunk-SNPZMRBC.js.map} +0 -0
@@ -1,18 +1,20 @@
1
1
  import {
2
- createAdapterAutoDetector,
3
- createAdapterRegistry,
2
+ SyncTrackingAdapter,
4
3
  createSupabaseAdapter,
4
+ getPowerSyncAlias,
5
5
  stripSchemaPrefix
6
- } from "./chunk-LG3OHLGB.js";
6
+ } from "./chunk-FWCHS5NN.js";
7
7
  import {
8
8
  DataLayerContext,
9
9
  DataLayerCoreContext,
10
10
  DataLayerNestingContext,
11
11
  DataLayerStatusContext
12
- } from "./chunk-GWYTROSD.js";
12
+ } from "./chunk-L4DFVMTS.js";
13
13
  import {
14
- QueryExecutor
15
- } from "./chunk-YRIPM2AN.js";
14
+ QueryExecutor,
15
+ transformResultsFromStorage,
16
+ transformWithRelations
17
+ } from "./chunk-4PZ744G2.js";
16
18
  import {
17
19
  extractRelationNames,
18
20
  parseSelect
@@ -1000,112 +1002,6 @@ var require_es = __commonJS({
1000
1002
  }
1001
1003
  });
1002
1004
 
1003
- // src/utils/type-transformer.ts
1004
- var columnMapCache = /* @__PURE__ */ new WeakMap();
1005
- function getOrCreateSchemaCache(schema) {
1006
- let cache = columnMapCache.get(schema);
1007
- if (!cache) {
1008
- cache = /* @__PURE__ */ new Map();
1009
- columnMapCache.set(schema, cache);
1010
- }
1011
- return cache;
1012
- }
1013
- function transformValueFromStorage(value, columnInfo) {
1014
- if (value === null || value === void 0) {
1015
- return value;
1016
- }
1017
- switch (columnInfo.type) {
1018
- case "boolean":
1019
- if (typeof value === "number") {
1020
- return value === 1;
1021
- }
1022
- if (typeof value === "string") {
1023
- return value === "1" || value.toLowerCase() === "true";
1024
- }
1025
- return Boolean(value);
1026
- case "number":
1027
- if (typeof value === "string") {
1028
- const num = Number(value);
1029
- return isNaN(num) ? value : num;
1030
- }
1031
- return value;
1032
- case "date":
1033
- return value;
1034
- case "enum":
1035
- case "string":
1036
- default:
1037
- return value;
1038
- }
1039
- }
1040
- function getColumnInfoMap(schema, tableName) {
1041
- const cache = getOrCreateSchemaCache(schema);
1042
- if (cache.has(tableName)) {
1043
- return cache.get(tableName);
1044
- }
1045
- const columnMap = /* @__PURE__ */ new Map();
1046
- for (const schemaName of Object.keys(schema.schemas)) {
1047
- const schemaData = schema.schemas[schemaName];
1048
- const table = schemaData.tables?.[tableName];
1049
- if (table) {
1050
- for (const col of table.columns) {
1051
- columnMap.set(col.name, col);
1052
- }
1053
- cache.set(tableName, columnMap);
1054
- return columnMap;
1055
- }
1056
- const view = schemaData.views?.[tableName];
1057
- if (view) {
1058
- for (const col of view.columns) {
1059
- columnMap.set(col.name, col);
1060
- }
1061
- cache.set(tableName, columnMap);
1062
- return columnMap;
1063
- }
1064
- }
1065
- cache.set(tableName, null);
1066
- return null;
1067
- }
1068
- function transformRowFromStorage(row, schema, tableName) {
1069
- const columnMap = getColumnInfoMap(schema, tableName);
1070
- if (!columnMap) {
1071
- return row;
1072
- }
1073
- const result = {};
1074
- for (const [key, value] of Object.entries(row)) {
1075
- const columnInfo = columnMap.get(key);
1076
- if (columnInfo) {
1077
- result[key] = transformValueFromStorage(value, columnInfo);
1078
- } else {
1079
- result[key] = value;
1080
- }
1081
- }
1082
- return result;
1083
- }
1084
- function transformResultsFromStorage(rows, schema, tableName) {
1085
- return rows.map((row) => transformRowFromStorage(row, schema, tableName));
1086
- }
1087
- function transformWithRelations(row, schema, tableName) {
1088
- const columnMap = getColumnInfoMap(schema, tableName);
1089
- const result = {};
1090
- for (const [key, value] of Object.entries(row)) {
1091
- if (value !== null && typeof value === "object" && !Array.isArray(value)) {
1092
- result[key] = transformWithRelations(value, schema, key);
1093
- } else if (Array.isArray(value) && value.length > 0 && typeof value[0] === "object") {
1094
- result[key] = value.map((item) => transformWithRelations(item, schema, key));
1095
- } else if (columnMap) {
1096
- const columnInfo = columnMap.get(key);
1097
- if (columnInfo) {
1098
- result[key] = transformValueFromStorage(value, columnInfo);
1099
- } else {
1100
- result[key] = value;
1101
- }
1102
- } else {
1103
- result[key] = value;
1104
- }
1105
- }
1106
- return result;
1107
- }
1108
-
1109
1005
  // src/adapters/powersync-adapter.ts
1110
1006
  import stringify from "fast-json-stable-stringify";
1111
1007
  var DEFAULT_MAX_SUBSCRIPTIONS = 100;
@@ -1120,7 +1016,6 @@ var PowerSyncAdapter = class {
1120
1016
  constructor(db, schema, options) {
1121
1017
  this.db = db;
1122
1018
  this.schema = schema;
1123
- this.executor = new QueryExecutor(db, schema);
1124
1019
  if (typeof options === "function") {
1125
1020
  this.tableNameResolver = options;
1126
1021
  this.maxSubscriptions = DEFAULT_MAX_SUBSCRIPTIONS;
@@ -1128,6 +1023,7 @@ var PowerSyncAdapter = class {
1128
1023
  this.tableNameResolver = options?.tableNameResolver;
1129
1024
  this.maxSubscriptions = options?.maxSubscriptions ?? DEFAULT_MAX_SUBSCRIPTIONS;
1130
1025
  }
1026
+ this.executor = new QueryExecutor(db, schema, this.tableNameResolver);
1131
1027
  }
1132
1028
  /**
1133
1029
  * Unique identifier for this adapter type
@@ -1494,12 +1390,13 @@ var PowerSyncAdapter = class {
1494
1390
  return this.schema;
1495
1391
  }
1496
1392
  };
1497
- function createPowerSyncAdapter(db, schema) {
1498
- return new PowerSyncAdapter(db, schema);
1393
+ function createPowerSyncAdapter(db, schema, options) {
1394
+ return new PowerSyncAdapter(db, schema, options);
1499
1395
  }
1500
1396
 
1501
1397
  // src/providers/DataLayerProvider.tsx
1502
- import { useState, useEffect, useLayoutEffect, useMemo, useCallback, useRef, useContext } from "react";
1398
+ import { c as _c } from "react/compiler-runtime";
1399
+ import { useRef, useEffect, useContext } from "react";
1503
1400
  import { jsx } from "react/jsx-runtime";
1504
1401
  var defaultSyncStatus = {
1505
1402
  isConnected: false,
@@ -1521,289 +1418,346 @@ var defaultSyncControl = {
1521
1418
  setScope: async () => {
1522
1419
  console.warn("Scope control not available: PowerSync not initialized");
1523
1420
  },
1524
- // Auto-retry controls
1525
- pauseAutoRetry: () => {
1526
- console.warn("Pause auto-retry not available: PowerSync not initialized");
1527
- },
1528
- resumeAutoRetry: () => {
1529
- console.warn("Resume auto-retry not available: PowerSync not initialized");
1530
- },
1531
- isAutoRetryPaused: false,
1532
- // Pending mutations
1533
1421
  addPendingMutation: () => {
1534
1422
  },
1535
1423
  removePendingMutation: () => {
1536
1424
  }
1537
1425
  };
1538
- function DataLayerProvider({
1539
- config,
1540
- children,
1541
- powerSyncInstance = null,
1542
- supabaseClient,
1543
- queryClient,
1544
- onInitialized,
1545
- onError,
1546
- powerSyncSyncStatus,
1547
- syncControl: externalSyncControl
1548
- }) {
1426
+ function DataLayerProvider(t0) {
1427
+ const $ = _c(70);
1428
+ const {
1429
+ config,
1430
+ children,
1431
+ powerSyncInstance: t1,
1432
+ supabaseClient,
1433
+ queryClient,
1434
+ syncControl: externalSyncControl,
1435
+ powerSyncSyncStatus
1436
+ } = t0;
1437
+ const powerSyncInstance = t1 === void 0 ? null : t1;
1438
+ const hasSynced = powerSyncSyncStatus?.hasSynced ?? (powerSyncInstance ? false : true);
1439
+ const isOnline = powerSyncSyncStatus?.isOnline ?? (typeof navigator !== "undefined" ? navigator.onLine : false);
1549
1440
  const isNested = useContext(DataLayerNestingContext);
1550
1441
  const hasWarnedNesting = useRef(false);
1551
- if (isNested && !hasWarnedNesting.current && typeof __DEV__ !== "undefined" && __DEV__) {
1552
- hasWarnedNesting.current = true;
1553
- console.warn("[DataLayerProvider] Nested DataLayerProvider detected! This usually indicates a setup issue where DataLayerProvider is wrapped twice. Each DataLayerProvider creates its own registry, which can cause:\n - Queries using wrong adapter (e.g., Supabase instead of PowerSync)\n - Inconsistent cache state\n - Unexpected behavior with sync status\n\nCommon causes:\n - Using both DataLayerWrapper and OfflineDataProvider (OfflineDataProvider already includes DataLayerProvider)\n - Accidentally wrapping layout twice\n\nFix: Remove the outer DataLayerProvider wrapper.");
1442
+ let t2;
1443
+ let t3;
1444
+ if ($[0] !== isNested) {
1445
+ t2 = () => {
1446
+ if (isNested && !hasWarnedNesting.current && typeof __DEV__ !== "undefined" && __DEV__) {
1447
+ hasWarnedNesting.current = true;
1448
+ console.warn("[DataLayerProvider] Nested DataLayerProvider detected! This usually indicates a setup issue. Remove the outer wrapper.");
1449
+ }
1450
+ };
1451
+ t3 = [isNested];
1452
+ $[0] = isNested;
1453
+ $[1] = t2;
1454
+ $[2] = t3;
1455
+ } else {
1456
+ t2 = $[1];
1457
+ t3 = $[2];
1554
1458
  }
1555
- const [registry] = useState(() => createAdapterRegistry(config));
1556
- const powerSyncInstanceRef = useRef(powerSyncInstance);
1557
- useLayoutEffect(() => {
1558
- powerSyncInstanceRef.current = powerSyncInstance;
1559
- registry.setPowerSyncGetter(() => powerSyncInstanceRef.current, (db) => createPowerSyncAdapter(db, config.schema));
1560
- }, [powerSyncInstance, registry, config.schema]);
1561
- const resolvedSyncControl = useMemo(() => externalSyncControl ?? defaultSyncControl, [externalSyncControl]);
1562
- const [isInitializedOnce, setIsInitializedOnce] = useState(false);
1563
- const [autoDetector, setAutoDetector] = useState(null);
1564
- const [status, setStatus] = useState({
1565
- isInitialized: false,
1566
- currentBackend: null,
1567
- powerSyncStatus: "unavailable" /* UNAVAILABLE */,
1568
- isOnline: powerSyncSyncStatus?.isOnline ?? (typeof navigator !== "undefined" ? navigator.onLine : true),
1569
- lastDetection: null,
1570
- error: null,
1571
- hasSynced: powerSyncSyncStatus?.hasSynced ?? false
1572
- });
1573
- useEffect(() => {
1574
- try {
1575
- const detector = createAdapterAutoDetector(powerSyncInstance, supabaseClient, {
1576
- preferPowerSync: true,
1577
- useOnlineUntilSynced: config.initialSync?.useOnlineUntilSynced ?? true
1459
+ useEffect(t2, t3);
1460
+ const syncControl = externalSyncControl ?? defaultSyncControl;
1461
+ let t4;
1462
+ if ($[3] !== config.tables) {
1463
+ t4 = (table) => {
1464
+ const tableWithoutSchema = table.includes(".") ? stripSchemaPrefix(table) : table;
1465
+ return config.tables[table] ?? config.tables[tableWithoutSchema];
1466
+ };
1467
+ $[3] = config.tables;
1468
+ $[4] = t4;
1469
+ } else {
1470
+ t4 = $[4];
1471
+ }
1472
+ const getTableStrategy = t4;
1473
+ let t5;
1474
+ if ($[5] !== config.tables) {
1475
+ t5 = (table_0) => {
1476
+ const tableWithoutSchema_0 = table_0.includes(".") ? stripSchemaPrefix(table_0) : table_0;
1477
+ const strategy = config.tables[table_0] ?? config.tables[tableWithoutSchema_0];
1478
+ const configKey = config.tables[table_0] ? table_0 : tableWithoutSchema_0;
1479
+ return getPowerSyncAlias(configKey, strategy);
1480
+ };
1481
+ $[5] = config.tables;
1482
+ $[6] = t5;
1483
+ } else {
1484
+ t5 = $[6];
1485
+ }
1486
+ const getTableAlias = t5;
1487
+ let t6;
1488
+ if ($[7] !== config.schema || $[8] !== supabaseClient) {
1489
+ t6 = createSupabaseAdapter(supabaseClient, config.schema);
1490
+ $[7] = config.schema;
1491
+ $[8] = supabaseClient;
1492
+ $[9] = t6;
1493
+ } else {
1494
+ t6 = $[9];
1495
+ }
1496
+ const supabaseAdapter = t6;
1497
+ let powerSyncAdapter = null;
1498
+ let syncTrackingAdapter = null;
1499
+ if (powerSyncInstance) {
1500
+ if ($[10] !== config.schema || $[11] !== externalSyncControl || $[12] !== getTableAlias || $[13] !== powerSyncInstance) {
1501
+ powerSyncAdapter = createPowerSyncAdapter(powerSyncInstance, config.schema, {
1502
+ tableNameResolver: getTableAlias
1578
1503
  });
1579
- setAutoDetector(detector);
1580
- const supabaseAdapter = createSupabaseAdapter(supabaseClient, config.schema);
1581
- registry.setSupabaseAdapter(supabaseAdapter);
1582
- if (powerSyncInstance) {
1583
- const powerSyncAdapter = createPowerSyncAdapter(powerSyncInstance, config.schema);
1584
- registry.setPowerSyncAdapter(powerSyncAdapter);
1504
+ if (externalSyncControl?.addPendingMutation) {
1505
+ syncTrackingAdapter = new SyncTrackingAdapter(powerSyncAdapter, {
1506
+ addPendingMutation: externalSyncControl.addPendingMutation,
1507
+ removePendingMutation: externalSyncControl.removePendingMutation
1508
+ });
1585
1509
  }
1586
- registry.setSyncTracker({
1587
- addPendingMutation: resolvedSyncControl.addPendingMutation,
1588
- removePendingMutation: resolvedSyncControl.removePendingMutation
1589
- });
1590
- registry.initialize({
1591
- powerSync: powerSyncInstance,
1592
- supabase: supabaseClient,
1593
- queryClient,
1594
- schema: config.schema
1595
- });
1596
- registry.initializeAutoDetection(detector);
1597
- const detection = detector.detect();
1598
- setStatus({
1599
- isInitialized: true,
1600
- currentBackend: detection.recommendedBackend,
1601
- powerSyncStatus: detection.powerSyncStatus,
1602
- isOnline: detection.isOnline,
1603
- lastDetection: detection,
1604
- error: null,
1605
- hasSynced: false
1606
- // Will be updated by Sync Status Update Effect
1607
- });
1608
- } catch (error) {
1609
- const err = error instanceof Error ? error : new Error(String(error));
1610
- setStatus((prev) => ({
1611
- ...prev,
1612
- error: err
1613
- }));
1614
- onError?.(err);
1615
- }
1616
- }, [powerSyncInstance, supabaseClient, queryClient, config.schema, registry, onError]);
1617
- useEffect(() => {
1618
- if (powerSyncSyncStatus?.isOnline !== void 0) {
1619
- return;
1510
+ $[10] = config.schema;
1511
+ $[11] = externalSyncControl;
1512
+ $[12] = getTableAlias;
1513
+ $[13] = powerSyncInstance;
1514
+ $[14] = powerSyncAdapter;
1515
+ $[15] = syncTrackingAdapter;
1516
+ } else {
1517
+ powerSyncAdapter = $[14];
1518
+ syncTrackingAdapter = $[15];
1620
1519
  }
1621
- const handleOnline = () => {
1622
- setStatus((prev) => ({
1623
- ...prev,
1624
- isOnline: true
1625
- }));
1626
- if (autoDetector) {
1627
- const detection = autoDetector.detect();
1628
- setStatus((prev) => ({
1629
- ...prev,
1630
- currentBackend: detection.recommendedBackend,
1631
- powerSyncStatus: detection.powerSyncStatus,
1632
- lastDetection: detection
1633
- }));
1634
- }
1520
+ }
1521
+ let t7;
1522
+ if ($[16] !== powerSyncAdapter || $[17] !== supabaseAdapter || $[18] !== syncTrackingAdapter) {
1523
+ t7 = {
1524
+ supabase: supabaseAdapter,
1525
+ powerSync: powerSyncAdapter,
1526
+ syncTracking: syncTrackingAdapter
1635
1527
  };
1636
- const handleOffline = () => {
1637
- setStatus((prev) => ({
1638
- ...prev,
1639
- isOnline: false
1640
- }));
1641
- if (autoDetector) {
1642
- const detection = autoDetector.detect();
1643
- setStatus((prev) => ({
1644
- ...prev,
1645
- currentBackend: detection.recommendedBackend,
1646
- powerSyncStatus: detection.powerSyncStatus,
1647
- lastDetection: detection
1648
- }));
1649
- }
1528
+ $[16] = powerSyncAdapter;
1529
+ $[17] = supabaseAdapter;
1530
+ $[18] = syncTrackingAdapter;
1531
+ $[19] = t7;
1532
+ } else {
1533
+ t7 = $[19];
1534
+ }
1535
+ const adapters = t7;
1536
+ let t8;
1537
+ if ($[20] !== getTableStrategy) {
1538
+ t8 = (table_1) => {
1539
+ const strategy_0 = getTableStrategy(table_1);
1540
+ return strategy_0?.strategy === "powersync" || strategy_0?.strategy === "hybrid" || strategy_0?.strategy === "auto" || !strategy_0;
1650
1541
  };
1651
- const isBrowser = typeof window !== "undefined" && typeof window.addEventListener === "function";
1652
- if (isBrowser) {
1653
- window.addEventListener("online", handleOnline);
1654
- window.addEventListener("offline", handleOffline);
1655
- return () => {
1656
- window.removeEventListener("online", handleOnline);
1657
- window.removeEventListener("offline", handleOffline);
1658
- };
1659
- }
1660
- }, [autoDetector, powerSyncSyncStatus?.isOnline]);
1661
- useEffect(() => {
1662
- if (!autoDetector) return;
1663
- const unsubscribe = autoDetector.addListener((detection) => {
1664
- setStatus((prev) => ({
1665
- ...prev,
1666
- currentBackend: detection.recommendedBackend,
1667
- powerSyncStatus: detection.powerSyncStatus,
1668
- isOnline: detection.isOnline,
1669
- lastDetection: detection
1670
- }));
1671
- });
1672
- return unsubscribe;
1673
- }, [autoDetector]);
1674
- useEffect(() => {
1675
- const currentDetector = registry.getAutoDetector();
1676
- if (!currentDetector) return;
1677
- if (powerSyncInstance && currentDetector.getPowerSync() !== powerSyncInstance) {
1678
- currentDetector.setPowerSyncDb(powerSyncInstance);
1679
- }
1680
- currentDetector.updateSyncStatus(powerSyncSyncStatus ?? null);
1681
- setStatus((prev) => {
1682
- const newHasSynced = powerSyncSyncStatus?.hasSynced ?? false;
1683
- const newIsOnline = powerSyncSyncStatus?.isOnline;
1684
- const hasSyncedChanged = prev.hasSynced !== newHasSynced;
1685
- const isOnlineChanged = newIsOnline !== void 0 && prev.isOnline !== newIsOnline;
1686
- if (!hasSyncedChanged && !isOnlineChanged) {
1687
- return prev;
1542
+ $[20] = getTableStrategy;
1543
+ $[21] = t8;
1544
+ } else {
1545
+ t8 = $[21];
1546
+ }
1547
+ const usesPowerSync = t8;
1548
+ let t9;
1549
+ if ($[22] !== config.tables) {
1550
+ t9 = () => Object.entries(config.tables).filter(_temp).map(_temp2);
1551
+ $[22] = config.tables;
1552
+ $[23] = t9;
1553
+ } else {
1554
+ t9 = $[23];
1555
+ }
1556
+ const getPowerSyncTables = t9;
1557
+ let t10;
1558
+ if ($[24] !== adapters.powerSync || $[25] !== adapters.supabase || $[26] !== adapters.syncTracking || $[27] !== config.tables || $[28] !== hasSynced || $[29] !== isOnline) {
1559
+ t10 = (table_2, t112) => {
1560
+ t112 === void 0 ? "read" : t112;
1561
+ const tableWithoutSchema_1 = table_2.includes(".") ? stripSchemaPrefix(table_2) : table_2;
1562
+ const strategy_3 = config.tables[table_2] ?? config.tables[tableWithoutSchema_1];
1563
+ if (strategy_3?.strategy === "supabase") {
1564
+ return adapters.supabase;
1688
1565
  }
1689
- return {
1690
- ...prev,
1691
- hasSynced: newHasSynced,
1692
- ...newIsOnline !== void 0 && {
1693
- isOnline: newIsOnline
1566
+ if (strategy_3?.strategy === "cached") {
1567
+ return adapters.supabase;
1568
+ }
1569
+ if (strategy_3?.strategy === "powersync") {
1570
+ if (adapters.powerSync) {
1571
+ return adapters.syncTracking ?? adapters.powerSync;
1694
1572
  }
1695
- };
1696
- });
1697
- }, [
1698
- // Note: We use registry.getAutoDetector() instead of autoDetector state
1699
- // to avoid race conditions. The registry is stable and always has the latest detector.
1700
- registry,
1701
- powerSyncInstance,
1702
- powerSyncSyncStatus?.hasSynced,
1703
- powerSyncSyncStatus?.connected,
1704
- powerSyncSyncStatus?.connecting,
1705
- powerSyncSyncStatus?.isOnline
1706
- ]);
1707
- useEffect(() => {
1708
- if (registry) {
1709
- registry.setSyncTracker({
1710
- addPendingMutation: resolvedSyncControl.addPendingMutation,
1711
- removePendingMutation: resolvedSyncControl.removePendingMutation
1712
- });
1713
- }
1714
- }, [resolvedSyncControl, registry]);
1715
- useEffect(() => {
1716
- if (status.isInitialized && !status.error && onInitialized) {
1717
- const contextValue2 = buildContextValue();
1718
- if (contextValue2) {
1719
- onInitialized(contextValue2);
1573
+ return adapters.supabase;
1720
1574
  }
1721
- }
1722
- }, [status.isInitialized, status.error]);
1723
- useEffect(() => {
1724
- if (status.isInitialized && !isInitializedOnce) {
1725
- setIsInitializedOnce(true);
1726
- }
1727
- }, [status.isInitialized, isInitializedOnce]);
1728
- const getAdapter = useCallback((table, operation = "read") => {
1729
- return registry.getAdapter(table, operation);
1730
- }, [registry]);
1731
- const buildContextValue = useCallback(() => {
1732
- if (!status.isInitialized) return null;
1733
- return {
1734
- registry,
1575
+ const isAutoTable = !strategy_3 || strategy_3.strategy === "auto" || strategy_3.strategy === "hybrid";
1576
+ if (isAutoTable) {
1577
+ const powerSyncTableKeys = Object.keys(config.tables).filter((key_0) => {
1578
+ const s = config.tables[key_0];
1579
+ return s.strategy === "powersync" || s.strategy === "hybrid" || s.strategy === "auto";
1580
+ });
1581
+ const isConfigured = powerSyncTableKeys.some((key_1) => key_1 === table_2 || key_1 === tableWithoutSchema_1 || key_1.includes(".") && key_1.split(".")[1] === tableWithoutSchema_1);
1582
+ if (!isConfigured) {
1583
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
1584
+ console.warn(`[DataLayerProvider] Table "${table_2}" is not configured for PowerSync. Using Supabase fallback.`);
1585
+ }
1586
+ return adapters.supabase;
1587
+ }
1588
+ if (isOnline && !hasSynced) {
1589
+ return adapters.supabase;
1590
+ }
1591
+ if (adapters.powerSync) {
1592
+ return adapters.syncTracking ?? adapters.powerSync;
1593
+ }
1594
+ }
1595
+ if (!adapters.supabase) {
1596
+ throw new Error(`No adapter available for table "${table_2}". Ensure Supabase client is properly initialized.`);
1597
+ }
1598
+ return adapters.supabase;
1599
+ };
1600
+ $[24] = adapters.powerSync;
1601
+ $[25] = adapters.supabase;
1602
+ $[26] = adapters.syncTracking;
1603
+ $[27] = config.tables;
1604
+ $[28] = hasSynced;
1605
+ $[29] = isOnline;
1606
+ $[30] = t10;
1607
+ } else {
1608
+ t10 = $[30];
1609
+ }
1610
+ const getAdapter = t10;
1611
+ let t11;
1612
+ if ($[31] !== adapters.powerSync || $[32] !== config.tables || $[33] !== getPowerSyncTables) {
1613
+ t11 = () => ({
1614
+ isInitialized: true,
1615
+ hasPowerSync: adapters.powerSync !== null,
1616
+ hasSupabase: true,
1617
+ configuredTableCount: Object.keys(config.tables).length,
1618
+ powerSyncTables: getPowerSyncTables()
1619
+ });
1620
+ $[31] = adapters.powerSync;
1621
+ $[32] = config.tables;
1622
+ $[33] = getPowerSyncTables;
1623
+ $[34] = t11;
1624
+ } else {
1625
+ t11 = $[34];
1626
+ }
1627
+ let t12;
1628
+ if ($[35] !== config || $[36] !== getAdapter || $[37] !== getPowerSyncTables || $[38] !== getTableAlias || $[39] !== getTableStrategy || $[40] !== t11 || $[41] !== usesPowerSync) {
1629
+ t12 = {
1735
1630
  getAdapter,
1736
- powerSync: powerSyncInstance,
1737
- supabase: supabaseClient,
1738
- queryClient,
1739
- schema: config.schema,
1740
- status,
1741
- syncStatus: defaultSyncStatus,
1742
- syncControl: resolvedSyncControl
1631
+ getTableStrategy,
1632
+ usesPowerSync,
1633
+ getPowerSyncTables,
1634
+ getTableAlias,
1635
+ getDebugInfo: t11,
1636
+ config,
1637
+ isInitialized: true
1743
1638
  };
1744
- }, [registry, getAdapter, powerSyncInstance, supabaseClient, queryClient, config.schema, status, resolvedSyncControl]);
1745
- const coreContextValue = useMemo(() => {
1746
- if (!isInitializedOnce) return null;
1747
- return {
1639
+ $[35] = config;
1640
+ $[36] = getAdapter;
1641
+ $[37] = getPowerSyncTables;
1642
+ $[38] = getTableAlias;
1643
+ $[39] = getTableStrategy;
1644
+ $[40] = t11;
1645
+ $[41] = usesPowerSync;
1646
+ $[42] = t12;
1647
+ } else {
1648
+ t12 = $[42];
1649
+ }
1650
+ const registry = t12;
1651
+ let t13;
1652
+ if ($[43] !== config.schema || $[44] !== getAdapter || $[45] !== powerSyncInstance || $[46] !== queryClient || $[47] !== registry || $[48] !== supabaseClient || $[49] !== syncControl) {
1653
+ t13 = {
1748
1654
  registry,
1749
1655
  getAdapter,
1750
1656
  powerSync: powerSyncInstance,
1751
1657
  supabase: supabaseClient,
1752
1658
  queryClient,
1753
1659
  schema: config.schema,
1754
- syncControl: resolvedSyncControl
1660
+ syncControl
1755
1661
  };
1756
- }, [isInitializedOnce, registry, getAdapter, powerSyncInstance, supabaseClient, queryClient, config.schema, resolvedSyncControl]);
1757
- const statusContextValue = useMemo(() => {
1758
- if (!status.isInitialized) return null;
1759
- return {
1662
+ $[43] = config.schema;
1663
+ $[44] = getAdapter;
1664
+ $[45] = powerSyncInstance;
1665
+ $[46] = queryClient;
1666
+ $[47] = registry;
1667
+ $[48] = supabaseClient;
1668
+ $[49] = syncControl;
1669
+ $[50] = t13;
1670
+ } else {
1671
+ t13 = $[50];
1672
+ }
1673
+ const coreContextValue = t13;
1674
+ const t14 = powerSyncInstance ? "powersync" : "supabase";
1675
+ const t15 = powerSyncInstance ? "available" /* AVAILABLE */ : "unavailable" /* UNAVAILABLE */;
1676
+ let t16;
1677
+ if ($[51] !== hasSynced || $[52] !== isOnline || $[53] !== t14 || $[54] !== t15) {
1678
+ t16 = {
1679
+ isInitialized: true,
1680
+ currentBackend: t14,
1681
+ powerSyncStatus: t15,
1682
+ isOnline,
1683
+ lastDetection: null,
1684
+ error: null,
1685
+ hasSynced
1686
+ };
1687
+ $[51] = hasSynced;
1688
+ $[52] = isOnline;
1689
+ $[53] = t14;
1690
+ $[54] = t15;
1691
+ $[55] = t16;
1692
+ } else {
1693
+ t16 = $[55];
1694
+ }
1695
+ const status = t16;
1696
+ let t17;
1697
+ if ($[56] !== status) {
1698
+ t17 = {
1760
1699
  status,
1761
1700
  syncStatus: defaultSyncStatus
1762
1701
  };
1763
- }, [status]);
1764
- const contextValue = useMemo(() => {
1765
- if (!coreContextValue || !statusContextValue) return null;
1766
- return {
1702
+ $[56] = status;
1703
+ $[57] = t17;
1704
+ } else {
1705
+ t17 = $[57];
1706
+ }
1707
+ const statusContextValue = t17;
1708
+ let t18;
1709
+ if ($[58] !== coreContextValue || $[59] !== statusContextValue) {
1710
+ t18 = {
1767
1711
  ...coreContextValue,
1768
1712
  ...statusContextValue
1769
1713
  };
1770
- }, [coreContextValue, statusContextValue]);
1771
- useEffect(() => {
1772
- return () => {
1773
- registry.dispose();
1774
- };
1775
- }, [registry]);
1776
- const pendingCoreContextValue = useMemo(
1777
- () => ({
1778
- registry,
1779
- getAdapter: () => {
1780
- throw new Error("DataLayer not yet initialized");
1781
- },
1782
- powerSync: null,
1783
- supabase: supabaseClient,
1784
- queryClient,
1785
- schema: config.schema,
1786
- syncControl: resolvedSyncControl
1787
- }),
1788
- // Only recompute when these stable deps change not on every status update
1789
- [registry, supabaseClient, queryClient, config.schema, resolvedSyncControl]
1790
- );
1791
- const pendingStatusContextValue = useMemo(() => ({
1792
- status,
1793
- syncStatus: defaultSyncStatus
1794
- }), [status]);
1795
- const pendingContextValue = useMemo(() => ({
1796
- ...pendingCoreContextValue,
1797
- ...pendingStatusContextValue
1798
- }), [pendingCoreContextValue, pendingStatusContextValue]);
1799
- const resolvedCore = coreContextValue ?? pendingCoreContextValue;
1800
- const resolvedStatus = statusContextValue ?? pendingStatusContextValue;
1801
- const resolvedContext = contextValue ?? pendingContextValue;
1802
- return /* @__PURE__ */ jsx(DataLayerNestingContext.Provider, { value: true, children: /* @__PURE__ */ jsx(DataLayerContext.Provider, { value: resolvedContext, children: /* @__PURE__ */ jsx(DataLayerCoreContext.Provider, { value: resolvedCore, children: /* @__PURE__ */ jsx(DataLayerStatusContext.Provider, { value: resolvedStatus, children }) }) }) });
1714
+ $[58] = coreContextValue;
1715
+ $[59] = statusContextValue;
1716
+ $[60] = t18;
1717
+ } else {
1718
+ t18 = $[60];
1719
+ }
1720
+ const contextValue = t18;
1721
+ let t19;
1722
+ if ($[61] !== children || $[62] !== statusContextValue) {
1723
+ t19 = /* @__PURE__ */ jsx(DataLayerStatusContext.Provider, { value: statusContextValue, children });
1724
+ $[61] = children;
1725
+ $[62] = statusContextValue;
1726
+ $[63] = t19;
1727
+ } else {
1728
+ t19 = $[63];
1729
+ }
1730
+ let t20;
1731
+ if ($[64] !== coreContextValue || $[65] !== t19) {
1732
+ t20 = /* @__PURE__ */ jsx(DataLayerCoreContext.Provider, { value: coreContextValue, children: t19 });
1733
+ $[64] = coreContextValue;
1734
+ $[65] = t19;
1735
+ $[66] = t20;
1736
+ } else {
1737
+ t20 = $[66];
1738
+ }
1739
+ let t21;
1740
+ if ($[67] !== contextValue || $[68] !== t20) {
1741
+ t21 = /* @__PURE__ */ jsx(DataLayerNestingContext.Provider, { value: true, children: /* @__PURE__ */ jsx(DataLayerContext.Provider, { value: contextValue, children: t20 }) });
1742
+ $[67] = contextValue;
1743
+ $[68] = t20;
1744
+ $[69] = t21;
1745
+ } else {
1746
+ t21 = $[69];
1747
+ }
1748
+ return t21;
1749
+ }
1750
+ function _temp2(t0) {
1751
+ const [key, strategy_2] = t0;
1752
+ return getPowerSyncAlias(key, strategy_2);
1753
+ }
1754
+ function _temp(t0) {
1755
+ const [, strategy_1] = t0;
1756
+ return strategy_1.strategy === "powersync" || strategy_1.strategy === "hybrid" || strategy_1.strategy === "auto";
1803
1757
  }
1804
1758
 
1805
1759
  // src/storage/use-supabase-upload.tsx
1806
- import { useCallback as useCallback3, useEffect as useEffect3, useMemo as useMemo3, useState as useState2 } from "react";
1760
+ import { useCallback as useCallback3, useEffect as useEffect3, useMemo as useMemo3, useState } from "react";
1807
1761
 
1808
1762
  // ../../../node_modules/.pnpm/react-dropzone@14.3.8_react@19.2.0/node_modules/react-dropzone/dist/es/index.js
1809
1763
  var import_prop_types = __toESM(require_prop_types(), 1);
@@ -4220,10 +4174,10 @@ var useSupabaseUpload = (options) => {
4220
4174
  cacheControl = 3600,
4221
4175
  upsert = false
4222
4176
  } = options;
4223
- const [files, setFiles] = useState2([]);
4224
- const [loading, setLoading] = useState2(false);
4225
- const [errors, setErrors] = useState2([]);
4226
- const [successes, setSuccesses] = useState2([]);
4177
+ const [files, setFiles] = useState([]);
4178
+ const [loading, setLoading] = useState(false);
4179
+ const [errors, setErrors] = useState([]);
4180
+ const [successes, setSuccesses] = useState([]);
4227
4181
  const isSuccess = useMemo3(() => {
4228
4182
  if (errors.length === 0 && successes.length === 0) {
4229
4183
  return false;
@@ -4327,7 +4281,7 @@ var useSupabaseUpload = (options) => {
4327
4281
  };
4328
4282
 
4329
4283
  // src/conflicts/ConflictContext.tsx
4330
- import { c as _c } from "react/compiler-runtime";
4284
+ import { c as _c2 } from "react/compiler-runtime";
4331
4285
  import { createContext, useEffect as useEffect4, useReducer as useReducer2, useRef as useRef3 } from "react";
4332
4286
 
4333
4287
  // src/conflicts/storage.ts
@@ -4479,7 +4433,7 @@ function conflictReducer(state, action) {
4479
4433
  }
4480
4434
  }
4481
4435
  function ConflictProvider(t0) {
4482
- const $ = _c(29);
4436
+ const $ = _c2(29);
4483
4437
  const {
4484
4438
  children,
4485
4439
  conflictBus
@@ -4513,7 +4467,7 @@ function ConflictProvider(t0) {
4513
4467
  conflicts
4514
4468
  });
4515
4469
  }
4516
- }).catch(_temp).finally(() => {
4470
+ }).catch(_temp3).finally(() => {
4517
4471
  hasFinishedLoadingRef.current = true;
4518
4472
  });
4519
4473
  };
@@ -4541,7 +4495,7 @@ function ConflictProvider(t0) {
4541
4495
  updatedTimestamps.set(key, now);
4542
4496
  }
4543
4497
  }
4544
- const currentKeys = new Set(state.pendingConflicts.map(_temp2));
4498
+ const currentKeys = new Set(state.pendingConflicts.map(_temp22));
4545
4499
  for (const key_0 of updatedTimestamps.keys()) {
4546
4500
  if (!currentKeys.has(key_0)) {
4547
4501
  updatedTimestamps.delete(key_0);
@@ -4721,15 +4675,15 @@ function ConflictProvider(t0) {
4721
4675
  }
4722
4676
  return t17;
4723
4677
  }
4724
- function _temp2(c) {
4678
+ function _temp22(c) {
4725
4679
  return `${c.table}:${c.recordId}`;
4726
4680
  }
4727
- function _temp(err) {
4681
+ function _temp3(err) {
4728
4682
  console.warn("[ConflictProvider] Failed to load conflicts:", err);
4729
4683
  }
4730
4684
 
4731
4685
  // src/conflicts/useConflictState.ts
4732
- import { c as _c2 } from "react/compiler-runtime";
4686
+ import { c as _c3 } from "react/compiler-runtime";
4733
4687
  import { useContext as useContext2 } from "react";
4734
4688
  function useConflictState() {
4735
4689
  const context = useContext2(ConflictContext);
@@ -4739,7 +4693,7 @@ function useConflictState() {
4739
4693
  return context;
4740
4694
  }
4741
4695
  function usePendingConflicts() {
4742
- const $ = _c2(2);
4696
+ const $ = _c3(2);
4743
4697
  const context = useContext2(ConflictContext);
4744
4698
  let t0;
4745
4699
  if ($[0] !== context?.pendingConflicts) {
@@ -4756,7 +4710,7 @@ function useHasConflicts() {
4756
4710
  return context?.hasConflicts ?? false;
4757
4711
  }
4758
4712
  function useConflictForRecord(table, recordId) {
4759
- const $ = _c2(4);
4713
+ const $ = _c3(4);
4760
4714
  const conflicts = usePendingConflicts();
4761
4715
  let t0;
4762
4716
  if ($[0] !== conflicts || $[1] !== recordId || $[2] !== table) {
@@ -4771,7 +4725,7 @@ function useConflictForRecord(table, recordId) {
4771
4725
  return t0;
4772
4726
  }
4773
4727
  function useConflictsForTable(table) {
4774
- const $ = _c2(5);
4728
+ const $ = _c3(5);
4775
4729
  const conflicts = usePendingConflicts();
4776
4730
  let t0;
4777
4731
  if ($[0] !== conflicts || $[1] !== table) {
@@ -4793,7 +4747,7 @@ function useConflictsForTable(table) {
4793
4747
  return t0;
4794
4748
  }
4795
4749
  function useConflictCountByTable() {
4796
- const $ = _c2(2);
4750
+ const $ = _c3(2);
4797
4751
  const conflicts = usePendingConflicts();
4798
4752
  let counts;
4799
4753
  if ($[0] !== conflicts) {
@@ -4810,9 +4764,9 @@ function useConflictCountByTable() {
4810
4764
  }
4811
4765
 
4812
4766
  // src/conflicts/useConflictResolution.ts
4813
- import { c as _c3 } from "react/compiler-runtime";
4767
+ import { c as _c4 } from "react/compiler-runtime";
4814
4768
  function useConflictResolution(conflict) {
4815
- const $ = _c3(28);
4769
+ const $ = _c4(28);
4816
4770
  const {
4817
4771
  resolveConflict
4818
4772
  } = useConflictState();
@@ -4886,7 +4840,7 @@ function useConflictResolution(conflict) {
4886
4840
  const syncFields = t4;
4887
4841
  let t5;
4888
4842
  if ($[13] !== conflict.conflicts) {
4889
- t5 = new Set(conflict.conflicts.map(_temp3));
4843
+ t5 = new Set(conflict.conflicts.map(_temp4));
4890
4844
  $[13] = conflict.conflicts;
4891
4845
  $[14] = t5;
4892
4846
  } else {
@@ -4948,11 +4902,11 @@ function useConflictResolution(conflict) {
4948
4902
  }
4949
4903
  return t8;
4950
4904
  }
4951
- function _temp3(c) {
4905
+ function _temp4(c) {
4952
4906
  return c.field;
4953
4907
  }
4954
4908
  function useBulkConflictResolution() {
4955
- const $ = _c3(13);
4909
+ const $ = _c4(13);
4956
4910
  const {
4957
4911
  resolveAll,
4958
4912
  resolveConflict,
@@ -5068,4 +5022,4 @@ object-assign/index.js:
5068
5022
  @license MIT
5069
5023
  *)
5070
5024
  */
5071
- //# sourceMappingURL=chunk-OK2C54B6.js.map
5025
+ //# sourceMappingURL=chunk-7PBTPCRN.js.map