@pol-studios/db 1.0.58 → 1.0.59

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 (49) 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-6SDH7M7J.js → chunk-ARALLEDJ.js} +2 -2
  8. package/dist/{chunk-Z456IHCB.js → chunk-F4HW4NT5.js} +1 -1
  9. package/dist/chunk-F4HW4NT5.js.map +1 -0
  10. package/dist/{chunk-OK2C54B6.js → chunk-K46TGKB2.js} +323 -379
  11. package/dist/chunk-K46TGKB2.js.map +1 -0
  12. package/dist/{chunk-GWYTROSD.js → chunk-L4DFVMTS.js} +335 -4
  13. package/dist/chunk-L4DFVMTS.js.map +1 -0
  14. package/dist/{chunk-MEBT5YHA.js → chunk-SNPZMRBC.js} +2 -2
  15. package/dist/{chunk-LG3OHLGB.js → chunk-VADZSRHY.js} +16 -337
  16. package/dist/chunk-VADZSRHY.js.map +1 -0
  17. package/dist/{chunk-4EO55YV2.js → chunk-VSY6766U.js} +4 -4
  18. package/dist/{chunk-VYFAMTHI.js → chunk-WY6MNB6K.js} +2 -2
  19. package/dist/core/index.d.ts +1 -1
  20. package/dist/{executor-D15yjeMo.d.ts → executor-Bu1OlqCl.d.ts} +43 -3
  21. package/dist/hooks/index.d.ts +3 -3
  22. package/dist/hooks/index.js +2 -2
  23. package/dist/{index-CFUuTzXO.d.ts → index-vwVJ0BWj.d.ts} +1 -9
  24. package/dist/index.d.ts +5 -5
  25. package/dist/index.js +20 -12
  26. package/dist/index.native.d.ts +77 -76
  27. package/dist/index.native.js +20 -12
  28. package/dist/index.web.d.ts +21 -44
  29. package/dist/index.web.js +215 -149
  30. package/dist/index.web.js.map +1 -1
  31. package/dist/powersync-bridge/index.d.ts +1 -1
  32. package/dist/query/index.d.ts +1 -1
  33. package/dist/query/index.js +1 -1
  34. package/dist/types/index.d.ts +3 -3
  35. package/dist/types/index.js +1 -1
  36. package/dist/{useDbCount-Ckb-FhZk.d.ts → useDbCount-dCkdaBpP.d.ts} +41 -83
  37. package/dist/{useResolveFeedback-CuUkdHoR.d.ts → useResolveFeedback-thFi-4h8.d.ts} +429 -5
  38. package/dist/with-auth/index.js +5 -5
  39. package/package.json +1 -1
  40. package/dist/DataLayerContext-BYZtDD0g.d.ts +0 -946
  41. package/dist/chunk-GWYTROSD.js.map +0 -1
  42. package/dist/chunk-LG3OHLGB.js.map +0 -1
  43. package/dist/chunk-OK2C54B6.js.map +0 -1
  44. package/dist/chunk-YRIPM2AN.js.map +0 -1
  45. package/dist/chunk-Z456IHCB.js.map +0 -1
  46. /package/dist/{chunk-6SDH7M7J.js.map → chunk-ARALLEDJ.js.map} +0 -0
  47. /package/dist/{chunk-MEBT5YHA.js.map → chunk-SNPZMRBC.js.map} +0 -0
  48. /package/dist/{chunk-4EO55YV2.js.map → chunk-VSY6766U.js.map} +0 -0
  49. /package/dist/{chunk-VYFAMTHI.js.map → chunk-WY6MNB6K.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-VADZSRHY.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,7 +1418,6 @@ var defaultSyncControl = {
1521
1418
  setScope: async () => {
1522
1419
  console.warn("Scope control not available: PowerSync not initialized");
1523
1420
  },
1524
- // Auto-retry controls
1525
1421
  pauseAutoRetry: () => {
1526
1422
  console.warn("Pause auto-retry not available: PowerSync not initialized");
1527
1423
  },
@@ -1529,281 +1425,329 @@ var defaultSyncControl = {
1529
1425
  console.warn("Resume auto-retry not available: PowerSync not initialized");
1530
1426
  },
1531
1427
  isAutoRetryPaused: false,
1532
- // Pending mutations
1533
1428
  addPendingMutation: () => {
1534
1429
  },
1535
1430
  removePendingMutation: () => {
1536
1431
  }
1537
1432
  };
1538
- function DataLayerProvider({
1539
- config,
1540
- children,
1541
- powerSyncInstance = null,
1542
- supabaseClient,
1543
- queryClient,
1544
- onInitialized,
1545
- onError,
1546
- powerSyncSyncStatus,
1547
- syncControl: externalSyncControl
1548
- }) {
1433
+ function DataLayerProvider(t0) {
1434
+ const $ = _c(68);
1435
+ const {
1436
+ config,
1437
+ children,
1438
+ powerSyncInstance: t1,
1439
+ supabaseClient,
1440
+ queryClient,
1441
+ syncControl: externalSyncControl,
1442
+ powerSyncSyncStatus
1443
+ } = t0;
1444
+ const powerSyncInstance = t1 === void 0 ? null : t1;
1445
+ const hasSynced = powerSyncSyncStatus?.hasSynced ?? (powerSyncInstance ? false : true);
1446
+ const isOnline = powerSyncSyncStatus?.isOnline ?? (typeof navigator !== "undefined" ? navigator.onLine : false);
1549
1447
  const isNested = useContext(DataLayerNestingContext);
1550
1448
  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.");
1449
+ let t2;
1450
+ let t3;
1451
+ if ($[0] !== isNested) {
1452
+ t2 = () => {
1453
+ if (isNested && !hasWarnedNesting.current && typeof __DEV__ !== "undefined" && __DEV__) {
1454
+ hasWarnedNesting.current = true;
1455
+ console.warn("[DataLayerProvider] Nested DataLayerProvider detected! This usually indicates a setup issue. Remove the outer wrapper.");
1456
+ }
1457
+ };
1458
+ t3 = [isNested];
1459
+ $[0] = isNested;
1460
+ $[1] = t2;
1461
+ $[2] = t3;
1462
+ } else {
1463
+ t2 = $[1];
1464
+ t3 = $[2];
1554
1465
  }
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
1466
+ useEffect(t2, t3);
1467
+ const syncControl = externalSyncControl ?? defaultSyncControl;
1468
+ let t4;
1469
+ if ($[3] !== config.tables) {
1470
+ t4 = (table) => {
1471
+ const tableWithoutSchema = table.includes(".") ? stripSchemaPrefix(table) : table;
1472
+ return config.tables[table] ?? config.tables[tableWithoutSchema];
1473
+ };
1474
+ $[3] = config.tables;
1475
+ $[4] = t4;
1476
+ } else {
1477
+ t4 = $[4];
1478
+ }
1479
+ const getTableStrategy = t4;
1480
+ let t5;
1481
+ if ($[5] !== config.tables) {
1482
+ t5 = (table_0) => {
1483
+ const tableWithoutSchema_0 = table_0.includes(".") ? stripSchemaPrefix(table_0) : table_0;
1484
+ const strategy = config.tables[table_0] ?? config.tables[tableWithoutSchema_0];
1485
+ const configKey = config.tables[table_0] ? table_0 : tableWithoutSchema_0;
1486
+ return getPowerSyncAlias(configKey, strategy);
1487
+ };
1488
+ $[5] = config.tables;
1489
+ $[6] = t5;
1490
+ } else {
1491
+ t5 = $[6];
1492
+ }
1493
+ const getTableAlias = t5;
1494
+ let t6;
1495
+ if ($[7] !== config.schema || $[8] !== supabaseClient) {
1496
+ t6 = createSupabaseAdapter(supabaseClient, config.schema);
1497
+ $[7] = config.schema;
1498
+ $[8] = supabaseClient;
1499
+ $[9] = t6;
1500
+ } else {
1501
+ t6 = $[9];
1502
+ }
1503
+ const supabaseAdapter = t6;
1504
+ let powerSyncAdapter = null;
1505
+ let syncTrackingAdapter = null;
1506
+ if (powerSyncInstance) {
1507
+ if ($[10] !== config.schema || $[11] !== externalSyncControl || $[12] !== getTableAlias || $[13] !== powerSyncInstance) {
1508
+ powerSyncAdapter = createPowerSyncAdapter(powerSyncInstance, config.schema, {
1509
+ tableNameResolver: getTableAlias
1578
1510
  });
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);
1511
+ if (externalSyncControl?.addPendingMutation) {
1512
+ syncTrackingAdapter = new SyncTrackingAdapter(powerSyncAdapter, {
1513
+ addPendingMutation: externalSyncControl.addPendingMutation,
1514
+ removePendingMutation: externalSyncControl.removePendingMutation
1515
+ });
1585
1516
  }
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;
1517
+ $[10] = config.schema;
1518
+ $[11] = externalSyncControl;
1519
+ $[12] = getTableAlias;
1520
+ $[13] = powerSyncInstance;
1521
+ $[14] = powerSyncAdapter;
1522
+ $[15] = syncTrackingAdapter;
1523
+ } else {
1524
+ powerSyncAdapter = $[14];
1525
+ syncTrackingAdapter = $[15];
1620
1526
  }
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
- }
1527
+ }
1528
+ let t7;
1529
+ if ($[16] !== powerSyncAdapter || $[17] !== supabaseAdapter || $[18] !== syncTrackingAdapter) {
1530
+ t7 = {
1531
+ supabase: supabaseAdapter,
1532
+ powerSync: powerSyncAdapter,
1533
+ syncTracking: syncTrackingAdapter
1635
1534
  };
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
- }
1535
+ $[16] = powerSyncAdapter;
1536
+ $[17] = supabaseAdapter;
1537
+ $[18] = syncTrackingAdapter;
1538
+ $[19] = t7;
1539
+ } else {
1540
+ t7 = $[19];
1541
+ }
1542
+ const adapters = t7;
1543
+ let t8;
1544
+ if ($[20] !== getTableStrategy) {
1545
+ t8 = (table_1) => {
1546
+ const strategy_0 = getTableStrategy(table_1);
1547
+ return strategy_0?.strategy === "powersync" || strategy_0?.strategy === "hybrid" || strategy_0?.strategy === "auto" || !strategy_0;
1650
1548
  };
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;
1549
+ $[20] = getTableStrategy;
1550
+ $[21] = t8;
1551
+ } else {
1552
+ t8 = $[21];
1553
+ }
1554
+ const usesPowerSync = t8;
1555
+ let t9;
1556
+ if ($[22] !== config.tables) {
1557
+ t9 = () => Object.entries(config.tables).filter(_temp).map(_temp2);
1558
+ $[22] = config.tables;
1559
+ $[23] = t9;
1560
+ } else {
1561
+ t9 = $[23];
1562
+ }
1563
+ const getPowerSyncTables = t9;
1564
+ let t10;
1565
+ if ($[24] !== adapters.powerSync || $[25] !== adapters.supabase || $[26] !== adapters.syncTracking || $[27] !== config.tables) {
1566
+ t10 = (table_2, t112) => {
1567
+ t112 === void 0 ? "read" : t112;
1568
+ const tableWithoutSchema_1 = table_2.includes(".") ? stripSchemaPrefix(table_2) : table_2;
1569
+ const strategy_3 = config.tables[table_2] ?? config.tables[tableWithoutSchema_1];
1570
+ if (strategy_3?.strategy === "supabase") {
1571
+ return adapters.supabase;
1688
1572
  }
1689
- return {
1690
- ...prev,
1691
- hasSynced: newHasSynced,
1692
- ...newIsOnline !== void 0 && {
1693
- isOnline: newIsOnline
1573
+ const isPowerSyncTable = !strategy_3 || strategy_3.strategy === "powersync" || strategy_3.strategy === "hybrid" || strategy_3.strategy === "auto";
1574
+ if (isPowerSyncTable && adapters.powerSync) {
1575
+ const powerSyncTableKeys = Object.keys(config.tables).filter((key_0) => {
1576
+ const s = config.tables[key_0];
1577
+ return s.strategy === "powersync" || s.strategy === "hybrid" || s.strategy === "auto";
1578
+ });
1579
+ const isConfigured = powerSyncTableKeys.some((key_1) => key_1 === table_2 || key_1 === tableWithoutSchema_1 || key_1.includes(".") && key_1.split(".")[1] === tableWithoutSchema_1);
1580
+ if (isConfigured) {
1581
+ return adapters.syncTracking ?? adapters.powerSync;
1582
+ }
1583
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
1584
+ console.warn(`[DataLayerProvider] Table "${table_2}" is not configured for PowerSync. Using Supabase fallback.`);
1694
1585
  }
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);
1720
1586
  }
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,
1587
+ if (!adapters.supabase) {
1588
+ throw new Error(`No adapter available for table "${table_2}". Ensure Supabase client is properly initialized.`);
1589
+ }
1590
+ return adapters.supabase;
1591
+ };
1592
+ $[24] = adapters.powerSync;
1593
+ $[25] = adapters.supabase;
1594
+ $[26] = adapters.syncTracking;
1595
+ $[27] = config.tables;
1596
+ $[28] = t10;
1597
+ } else {
1598
+ t10 = $[28];
1599
+ }
1600
+ const getAdapter = t10;
1601
+ let t11;
1602
+ if ($[29] !== adapters.powerSync || $[30] !== config.tables || $[31] !== getPowerSyncTables) {
1603
+ t11 = () => ({
1604
+ isInitialized: true,
1605
+ hasPowerSync: adapters.powerSync !== null,
1606
+ hasSupabase: true,
1607
+ configuredTableCount: Object.keys(config.tables).length,
1608
+ powerSyncTables: getPowerSyncTables()
1609
+ });
1610
+ $[29] = adapters.powerSync;
1611
+ $[30] = config.tables;
1612
+ $[31] = getPowerSyncTables;
1613
+ $[32] = t11;
1614
+ } else {
1615
+ t11 = $[32];
1616
+ }
1617
+ let t12;
1618
+ if ($[33] !== config || $[34] !== getAdapter || $[35] !== getPowerSyncTables || $[36] !== getTableAlias || $[37] !== getTableStrategy || $[38] !== t11 || $[39] !== usesPowerSync) {
1619
+ t12 = {
1735
1620
  getAdapter,
1736
- powerSync: powerSyncInstance,
1737
- supabase: supabaseClient,
1738
- queryClient,
1739
- schema: config.schema,
1740
- status,
1741
- syncStatus: defaultSyncStatus,
1742
- syncControl: resolvedSyncControl
1621
+ getTableStrategy,
1622
+ usesPowerSync,
1623
+ getPowerSyncTables,
1624
+ getTableAlias,
1625
+ getDebugInfo: t11,
1626
+ config,
1627
+ isInitialized: true
1743
1628
  };
1744
- }, [registry, getAdapter, powerSyncInstance, supabaseClient, queryClient, config.schema, status, resolvedSyncControl]);
1745
- const coreContextValue = useMemo(() => {
1746
- if (!isInitializedOnce) return null;
1747
- return {
1629
+ $[33] = config;
1630
+ $[34] = getAdapter;
1631
+ $[35] = getPowerSyncTables;
1632
+ $[36] = getTableAlias;
1633
+ $[37] = getTableStrategy;
1634
+ $[38] = t11;
1635
+ $[39] = usesPowerSync;
1636
+ $[40] = t12;
1637
+ } else {
1638
+ t12 = $[40];
1639
+ }
1640
+ const registry = t12;
1641
+ let t13;
1642
+ if ($[41] !== config.schema || $[42] !== getAdapter || $[43] !== powerSyncInstance || $[44] !== queryClient || $[45] !== registry || $[46] !== supabaseClient || $[47] !== syncControl) {
1643
+ t13 = {
1748
1644
  registry,
1749
1645
  getAdapter,
1750
1646
  powerSync: powerSyncInstance,
1751
1647
  supabase: supabaseClient,
1752
1648
  queryClient,
1753
1649
  schema: config.schema,
1754
- syncControl: resolvedSyncControl
1650
+ syncControl
1755
1651
  };
1756
- }, [isInitializedOnce, registry, getAdapter, powerSyncInstance, supabaseClient, queryClient, config.schema, resolvedSyncControl]);
1757
- const statusContextValue = useMemo(() => {
1758
- if (!status.isInitialized) return null;
1759
- return {
1652
+ $[41] = config.schema;
1653
+ $[42] = getAdapter;
1654
+ $[43] = powerSyncInstance;
1655
+ $[44] = queryClient;
1656
+ $[45] = registry;
1657
+ $[46] = supabaseClient;
1658
+ $[47] = syncControl;
1659
+ $[48] = t13;
1660
+ } else {
1661
+ t13 = $[48];
1662
+ }
1663
+ const coreContextValue = t13;
1664
+ const t14 = powerSyncInstance ? "powersync" : "supabase";
1665
+ const t15 = powerSyncInstance ? "available" /* AVAILABLE */ : "unavailable" /* UNAVAILABLE */;
1666
+ let t16;
1667
+ if ($[49] !== hasSynced || $[50] !== isOnline || $[51] !== t14 || $[52] !== t15) {
1668
+ t16 = {
1669
+ isInitialized: true,
1670
+ currentBackend: t14,
1671
+ powerSyncStatus: t15,
1672
+ isOnline,
1673
+ lastDetection: null,
1674
+ error: null,
1675
+ hasSynced
1676
+ };
1677
+ $[49] = hasSynced;
1678
+ $[50] = isOnline;
1679
+ $[51] = t14;
1680
+ $[52] = t15;
1681
+ $[53] = t16;
1682
+ } else {
1683
+ t16 = $[53];
1684
+ }
1685
+ const status = t16;
1686
+ let t17;
1687
+ if ($[54] !== status) {
1688
+ t17 = {
1760
1689
  status,
1761
1690
  syncStatus: defaultSyncStatus
1762
1691
  };
1763
- }, [status]);
1764
- const contextValue = useMemo(() => {
1765
- if (!coreContextValue || !statusContextValue) return null;
1766
- return {
1692
+ $[54] = status;
1693
+ $[55] = t17;
1694
+ } else {
1695
+ t17 = $[55];
1696
+ }
1697
+ const statusContextValue = t17;
1698
+ let t18;
1699
+ if ($[56] !== coreContextValue || $[57] !== statusContextValue) {
1700
+ t18 = {
1767
1701
  ...coreContextValue,
1768
1702
  ...statusContextValue
1769
1703
  };
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 }) }) }) });
1704
+ $[56] = coreContextValue;
1705
+ $[57] = statusContextValue;
1706
+ $[58] = t18;
1707
+ } else {
1708
+ t18 = $[58];
1709
+ }
1710
+ const contextValue = t18;
1711
+ let t19;
1712
+ if ($[59] !== children || $[60] !== statusContextValue) {
1713
+ t19 = /* @__PURE__ */ jsx(DataLayerStatusContext.Provider, { value: statusContextValue, children });
1714
+ $[59] = children;
1715
+ $[60] = statusContextValue;
1716
+ $[61] = t19;
1717
+ } else {
1718
+ t19 = $[61];
1719
+ }
1720
+ let t20;
1721
+ if ($[62] !== coreContextValue || $[63] !== t19) {
1722
+ t20 = /* @__PURE__ */ jsx(DataLayerCoreContext.Provider, { value: coreContextValue, children: t19 });
1723
+ $[62] = coreContextValue;
1724
+ $[63] = t19;
1725
+ $[64] = t20;
1726
+ } else {
1727
+ t20 = $[64];
1728
+ }
1729
+ let t21;
1730
+ if ($[65] !== contextValue || $[66] !== t20) {
1731
+ t21 = /* @__PURE__ */ jsx(DataLayerNestingContext.Provider, { value: true, children: /* @__PURE__ */ jsx(DataLayerContext.Provider, { value: contextValue, children: t20 }) });
1732
+ $[65] = contextValue;
1733
+ $[66] = t20;
1734
+ $[67] = t21;
1735
+ } else {
1736
+ t21 = $[67];
1737
+ }
1738
+ return t21;
1739
+ }
1740
+ function _temp2(t0) {
1741
+ const [key, strategy_2] = t0;
1742
+ return getPowerSyncAlias(key, strategy_2);
1743
+ }
1744
+ function _temp(t0) {
1745
+ const [, strategy_1] = t0;
1746
+ return strategy_1.strategy === "powersync" || strategy_1.strategy === "hybrid" || strategy_1.strategy === "auto";
1803
1747
  }
1804
1748
 
1805
1749
  // src/storage/use-supabase-upload.tsx
1806
- import { useCallback as useCallback3, useEffect as useEffect3, useMemo as useMemo3, useState as useState2 } from "react";
1750
+ import { useCallback as useCallback3, useEffect as useEffect3, useMemo as useMemo3, useState } from "react";
1807
1751
 
1808
1752
  // ../../../node_modules/.pnpm/react-dropzone@14.3.8_react@19.2.0/node_modules/react-dropzone/dist/es/index.js
1809
1753
  var import_prop_types = __toESM(require_prop_types(), 1);
@@ -4220,10 +4164,10 @@ var useSupabaseUpload = (options) => {
4220
4164
  cacheControl = 3600,
4221
4165
  upsert = false
4222
4166
  } = options;
4223
- const [files, setFiles] = useState2([]);
4224
- const [loading, setLoading] = useState2(false);
4225
- const [errors, setErrors] = useState2([]);
4226
- const [successes, setSuccesses] = useState2([]);
4167
+ const [files, setFiles] = useState([]);
4168
+ const [loading, setLoading] = useState(false);
4169
+ const [errors, setErrors] = useState([]);
4170
+ const [successes, setSuccesses] = useState([]);
4227
4171
  const isSuccess = useMemo3(() => {
4228
4172
  if (errors.length === 0 && successes.length === 0) {
4229
4173
  return false;
@@ -4327,7 +4271,7 @@ var useSupabaseUpload = (options) => {
4327
4271
  };
4328
4272
 
4329
4273
  // src/conflicts/ConflictContext.tsx
4330
- import { c as _c } from "react/compiler-runtime";
4274
+ import { c as _c2 } from "react/compiler-runtime";
4331
4275
  import { createContext, useEffect as useEffect4, useReducer as useReducer2, useRef as useRef3 } from "react";
4332
4276
 
4333
4277
  // src/conflicts/storage.ts
@@ -4479,7 +4423,7 @@ function conflictReducer(state, action) {
4479
4423
  }
4480
4424
  }
4481
4425
  function ConflictProvider(t0) {
4482
- const $ = _c(29);
4426
+ const $ = _c2(29);
4483
4427
  const {
4484
4428
  children,
4485
4429
  conflictBus
@@ -4513,7 +4457,7 @@ function ConflictProvider(t0) {
4513
4457
  conflicts
4514
4458
  });
4515
4459
  }
4516
- }).catch(_temp).finally(() => {
4460
+ }).catch(_temp3).finally(() => {
4517
4461
  hasFinishedLoadingRef.current = true;
4518
4462
  });
4519
4463
  };
@@ -4541,7 +4485,7 @@ function ConflictProvider(t0) {
4541
4485
  updatedTimestamps.set(key, now);
4542
4486
  }
4543
4487
  }
4544
- const currentKeys = new Set(state.pendingConflicts.map(_temp2));
4488
+ const currentKeys = new Set(state.pendingConflicts.map(_temp22));
4545
4489
  for (const key_0 of updatedTimestamps.keys()) {
4546
4490
  if (!currentKeys.has(key_0)) {
4547
4491
  updatedTimestamps.delete(key_0);
@@ -4721,15 +4665,15 @@ function ConflictProvider(t0) {
4721
4665
  }
4722
4666
  return t17;
4723
4667
  }
4724
- function _temp2(c) {
4668
+ function _temp22(c) {
4725
4669
  return `${c.table}:${c.recordId}`;
4726
4670
  }
4727
- function _temp(err) {
4671
+ function _temp3(err) {
4728
4672
  console.warn("[ConflictProvider] Failed to load conflicts:", err);
4729
4673
  }
4730
4674
 
4731
4675
  // src/conflicts/useConflictState.ts
4732
- import { c as _c2 } from "react/compiler-runtime";
4676
+ import { c as _c3 } from "react/compiler-runtime";
4733
4677
  import { useContext as useContext2 } from "react";
4734
4678
  function useConflictState() {
4735
4679
  const context = useContext2(ConflictContext);
@@ -4739,7 +4683,7 @@ function useConflictState() {
4739
4683
  return context;
4740
4684
  }
4741
4685
  function usePendingConflicts() {
4742
- const $ = _c2(2);
4686
+ const $ = _c3(2);
4743
4687
  const context = useContext2(ConflictContext);
4744
4688
  let t0;
4745
4689
  if ($[0] !== context?.pendingConflicts) {
@@ -4756,7 +4700,7 @@ function useHasConflicts() {
4756
4700
  return context?.hasConflicts ?? false;
4757
4701
  }
4758
4702
  function useConflictForRecord(table, recordId) {
4759
- const $ = _c2(4);
4703
+ const $ = _c3(4);
4760
4704
  const conflicts = usePendingConflicts();
4761
4705
  let t0;
4762
4706
  if ($[0] !== conflicts || $[1] !== recordId || $[2] !== table) {
@@ -4771,7 +4715,7 @@ function useConflictForRecord(table, recordId) {
4771
4715
  return t0;
4772
4716
  }
4773
4717
  function useConflictsForTable(table) {
4774
- const $ = _c2(5);
4718
+ const $ = _c3(5);
4775
4719
  const conflicts = usePendingConflicts();
4776
4720
  let t0;
4777
4721
  if ($[0] !== conflicts || $[1] !== table) {
@@ -4793,7 +4737,7 @@ function useConflictsForTable(table) {
4793
4737
  return t0;
4794
4738
  }
4795
4739
  function useConflictCountByTable() {
4796
- const $ = _c2(2);
4740
+ const $ = _c3(2);
4797
4741
  const conflicts = usePendingConflicts();
4798
4742
  let counts;
4799
4743
  if ($[0] !== conflicts) {
@@ -4810,9 +4754,9 @@ function useConflictCountByTable() {
4810
4754
  }
4811
4755
 
4812
4756
  // src/conflicts/useConflictResolution.ts
4813
- import { c as _c3 } from "react/compiler-runtime";
4757
+ import { c as _c4 } from "react/compiler-runtime";
4814
4758
  function useConflictResolution(conflict) {
4815
- const $ = _c3(28);
4759
+ const $ = _c4(28);
4816
4760
  const {
4817
4761
  resolveConflict
4818
4762
  } = useConflictState();
@@ -4886,7 +4830,7 @@ function useConflictResolution(conflict) {
4886
4830
  const syncFields = t4;
4887
4831
  let t5;
4888
4832
  if ($[13] !== conflict.conflicts) {
4889
- t5 = new Set(conflict.conflicts.map(_temp3));
4833
+ t5 = new Set(conflict.conflicts.map(_temp4));
4890
4834
  $[13] = conflict.conflicts;
4891
4835
  $[14] = t5;
4892
4836
  } else {
@@ -4948,11 +4892,11 @@ function useConflictResolution(conflict) {
4948
4892
  }
4949
4893
  return t8;
4950
4894
  }
4951
- function _temp3(c) {
4895
+ function _temp4(c) {
4952
4896
  return c.field;
4953
4897
  }
4954
4898
  function useBulkConflictResolution() {
4955
- const $ = _c3(13);
4899
+ const $ = _c4(13);
4956
4900
  const {
4957
4901
  resolveAll,
4958
4902
  resolveConflict,
@@ -5068,4 +5012,4 @@ object-assign/index.js:
5068
5012
  @license MIT
5069
5013
  *)
5070
5014
  */
5071
- //# sourceMappingURL=chunk-OK2C54B6.js.map
5015
+ //# sourceMappingURL=chunk-K46TGKB2.js.map