@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,21 +1,21 @@
1
1
  import {
2
2
  useDbUpsert
3
- } from "./chunk-VYFAMTHI.js";
3
+ } from "./chunk-WY6MNB6K.js";
4
4
  import {
5
5
  normalizeFilter
6
- } from "./chunk-Z456IHCB.js";
6
+ } from "./chunk-F4HW4NT5.js";
7
7
  import {
8
8
  OperationLog
9
9
  } from "./chunk-7SCJNYTE.js";
10
10
  import {
11
11
  useDbQuery
12
- } from "./chunk-6SDH7M7J.js";
12
+ } from "./chunk-ARALLEDJ.js";
13
13
  import {
14
14
  useDataLayerCoreOptional
15
- } from "./chunk-GWYTROSD.js";
15
+ } from "./chunk-L4DFVMTS.js";
16
16
  import {
17
17
  ResultJoiner
18
- } from "./chunk-YRIPM2AN.js";
18
+ } from "./chunk-4PZ744G2.js";
19
19
  import {
20
20
  getSupabaseUrl
21
21
  } from "./chunk-GC3TBUWE.js";
@@ -4279,6 +4279,14 @@ function stripSchemaPrefix(tableName) {
4279
4279
  }
4280
4280
  return tableName.split(".")[1];
4281
4281
  }
4282
+ function generatePowerSyncAlias(tableName) {
4283
+ if (!tableName.includes(".")) {
4284
+ return tableName;
4285
+ }
4286
+ const [schema, table] = tableName.split(".");
4287
+ const pascalSchema = schema.charAt(0).toUpperCase() + schema.slice(1);
4288
+ return `${pascalSchema}${table}`;
4289
+ }
4282
4290
  function getPowerSyncAlias(tableName, strategy) {
4283
4291
  if (strategy && (strategy.strategy === "powersync" || strategy.strategy === "hybrid")) {
4284
4292
  const typedStrategy = strategy;
@@ -4773,334 +4781,6 @@ function createAdapterRegistry(config) {
4773
4781
  return new AdapterRegistry(config);
4774
4782
  }
4775
4783
 
4776
- // src/adapters/auto-detector.ts
4777
- var BackendStatus = /* @__PURE__ */ ((BackendStatus2) => {
4778
- BackendStatus2["AVAILABLE"] = "available";
4779
- BackendStatus2["INITIALIZING"] = "initializing";
4780
- BackendStatus2["UNAVAILABLE"] = "unavailable";
4781
- return BackendStatus2;
4782
- })(BackendStatus || {});
4783
- var AdapterAutoDetector = class {
4784
- constructor(powerSyncDb, supabase, options = {}) {
4785
- this.powerSyncDb = powerSyncDb;
4786
- this.supabase = supabase;
4787
- this.options = {
4788
- preferPowerSync: options.preferPowerSync ?? true,
4789
- statusCheckTimeout: options.statusCheckTimeout ?? 1e3,
4790
- useOnlineUntilSynced: options.useOnlineUntilSynced ?? true
4791
- };
4792
- }
4793
- options;
4794
- listeners = /* @__PURE__ */ new Set();
4795
- lastResult = null;
4796
- syncStatus = null;
4797
- /**
4798
- * Update the PowerSync database reference.
4799
- * Called when PowerSync becomes available after initial construction.
4800
- *
4801
- * @param db - PowerSync database instance or null
4802
- */
4803
- setPowerSyncDb(db) {
4804
- this.powerSyncDb = db;
4805
- if (db) {
4806
- this.detectSilent();
4807
- }
4808
- }
4809
- /**
4810
- * Update the sync status from PowerSync.
4811
- * Called when sync status changes to re-evaluate backend recommendation.
4812
- *
4813
- * @param status - Current sync status or null if not available
4814
- */
4815
- updateSyncStatus(status) {
4816
- const hadSynced = this.syncStatus?.hasSynced;
4817
- const hasSyncedNow = status?.hasSynced;
4818
- const changed = hadSynced !== hasSyncedNow;
4819
- this.syncStatus = status;
4820
- if (changed) {
4821
- this.detect();
4822
- }
4823
- }
4824
- /**
4825
- * Get current sync status.
4826
- * @returns Current sync status or null
4827
- */
4828
- getSyncStatus() {
4829
- return this.syncStatus;
4830
- }
4831
- // ===========================================================================
4832
- // Main Detection Methods
4833
- // ===========================================================================
4834
- /**
4835
- * Detect backend availability and recommend best option.
4836
- *
4837
- * The detection logic follows this priority:
4838
- * 1. If preferPowerSync is true and PowerSync is available, use PowerSync
4839
- * 2. If PowerSync is initializing and online with Supabase available, use Supabase temporarily
4840
- * 3. If online with Supabase available, use Supabase
4841
- * 4. If offline but PowerSync available, use PowerSync (offline mode)
4842
- * 5. If offline and PowerSync exists (even if initializing), use PowerSync local data
4843
- * 6. Default to Supabase as fallback
4844
- *
4845
- * @returns Detection result with recommendation and reasoning
4846
- */
4847
- detect() {
4848
- const result = this.performDetection();
4849
- if (this.hasResultChanged(result)) {
4850
- this.lastResult = result;
4851
- this.notifyListeners(result);
4852
- }
4853
- return result;
4854
- }
4855
- /**
4856
- * Detect backend availability WITHOUT notifying listeners.
4857
- *
4858
- * This method is safe to call during React's render phase because it does not
4859
- * trigger state updates in other components. Use this method when you need to
4860
- * check backend status synchronously during render (e.g., in getAdapter()).
4861
- *
4862
- * The regular detect() method with listener notifications should only be called
4863
- * from useEffect or event handlers to avoid the React warning:
4864
- * "Cannot update a component while rendering a different component"
4865
- *
4866
- * @returns Detection result with recommendation and reasoning
4867
- */
4868
- detectSilent() {
4869
- const result = this.performDetection();
4870
- this.lastResult = result;
4871
- return result;
4872
- }
4873
- /**
4874
- * Internal detection logic shared by detect() and detectSilent().
4875
- * @private
4876
- */
4877
- performDetection() {
4878
- const powerSyncStatus = this.detectPowerSyncStatus();
4879
- const supabaseStatus = this.detectSupabaseStatus();
4880
- const isOnline = this.checkOnlineStatus();
4881
- let recommendedBackend;
4882
- let reason;
4883
- if (this.options.preferPowerSync && powerSyncStatus === "available" /* AVAILABLE */) {
4884
- recommendedBackend = "powersync";
4885
- reason = "PowerSync is available and preferred for offline-first experience";
4886
- } else if (powerSyncStatus === "initializing" /* INITIALIZING */ && isOnline && supabaseStatus === "available" /* AVAILABLE */) {
4887
- recommendedBackend = "supabase";
4888
- reason = "PowerSync initial sync in progress; using Supabase for fresh data";
4889
- } else if (supabaseStatus === "available" /* AVAILABLE */ && isOnline) {
4890
- recommendedBackend = "supabase";
4891
- reason = "Using Supabase direct connection";
4892
- } else if (powerSyncStatus === "available" /* AVAILABLE */) {
4893
- recommendedBackend = "powersync";
4894
- reason = "Offline mode using PowerSync local data";
4895
- } else if (!isOnline && this.powerSyncDb) {
4896
- recommendedBackend = "powersync";
4897
- reason = "Offline mode - using PowerSync local data (initial sync may be incomplete)";
4898
- } else {
4899
- recommendedBackend = "supabase";
4900
- reason = "No confirmed available backend; defaulting to Supabase";
4901
- }
4902
- return {
4903
- powerSyncStatus,
4904
- supabaseStatus,
4905
- recommendedBackend,
4906
- isOnline,
4907
- reason
4908
- };
4909
- }
4910
- /**
4911
- * Check if PowerSync is available.
4912
- *
4913
- * PowerSync status depends on:
4914
- * 1. Database instance exists
4915
- * 2. If useOnlineUntilSynced is true, also checks if initial sync completed
4916
- *
4917
- * @returns PowerSync backend status
4918
- */
4919
- detectPowerSyncStatus() {
4920
- if (!this.powerSyncDb) {
4921
- return "unavailable" /* UNAVAILABLE */;
4922
- }
4923
- try {
4924
- if (typeof this.powerSyncDb.getAll !== "function") {
4925
- return "initializing" /* INITIALIZING */;
4926
- }
4927
- if (this.options.useOnlineUntilSynced) {
4928
- if (!this.syncStatus || !this.syncStatus.hasSynced) {
4929
- return "initializing" /* INITIALIZING */;
4930
- }
4931
- }
4932
- return "available" /* AVAILABLE */;
4933
- } catch {
4934
- return "initializing" /* INITIALIZING */;
4935
- }
4936
- }
4937
- /**
4938
- * Check if Supabase is available.
4939
- *
4940
- * Supabase is considered available if we have a client instance.
4941
- * The actual network connectivity is checked separately via checkOnlineStatus().
4942
- *
4943
- * @returns Supabase backend status
4944
- */
4945
- detectSupabaseStatus() {
4946
- if (!this.supabase) {
4947
- return "unavailable" /* UNAVAILABLE */;
4948
- }
4949
- try {
4950
- if (typeof this.supabase.from === "function") {
4951
- return "available" /* AVAILABLE */;
4952
- }
4953
- return "unavailable" /* UNAVAILABLE */;
4954
- } catch {
4955
- return "unavailable" /* UNAVAILABLE */;
4956
- }
4957
- }
4958
- /**
4959
- * Check if device is online.
4960
- *
4961
- * Prefers the sync status's isOnline property if available (from React Native NetInfo).
4962
- * Falls back to navigator.onLine in browser environments.
4963
- * Returns false by default for non-browser environments (React Native, Node.js, etc.)
4964
- * to ensure offline-first behavior works correctly.
4965
- *
4966
- * @returns Whether the device has network connectivity
4967
- */
4968
- checkOnlineStatus() {
4969
- if (this.syncStatus?.isOnline !== void 0) {
4970
- return this.syncStatus.isOnline;
4971
- }
4972
- if (typeof window !== "undefined" && typeof navigator !== "undefined") {
4973
- return navigator.onLine;
4974
- }
4975
- return false;
4976
- }
4977
- // ===========================================================================
4978
- // Instance Management Methods
4979
- // ===========================================================================
4980
- /**
4981
- * Update PowerSync instance (e.g., when it becomes available).
4982
- *
4983
- * @param db - New PowerSync database instance or null
4984
- */
4985
- setPowerSync(db) {
4986
- this.powerSyncDb = db;
4987
- }
4988
- /**
4989
- * Update Supabase instance.
4990
- *
4991
- * @param supabase - New Supabase client instance or null
4992
- */
4993
- setSupabase(supabase) {
4994
- this.supabase = supabase;
4995
- }
4996
- /**
4997
- * Get current PowerSync instance.
4998
- *
4999
- * @returns Current PowerSync database instance or null
5000
- */
5001
- getPowerSync() {
5002
- return this.powerSyncDb;
5003
- }
5004
- /**
5005
- * Get current Supabase instance.
5006
- *
5007
- * @returns Current Supabase client instance or null
5008
- */
5009
- getSupabase() {
5010
- return this.supabase;
5011
- }
5012
- // ===========================================================================
5013
- // Options Management
5014
- // ===========================================================================
5015
- /**
5016
- * Update detector options.
5017
- *
5018
- * @param options - New options to merge with existing
5019
- */
5020
- setOptions(options) {
5021
- this.options = {
5022
- ...this.options,
5023
- ...options
5024
- };
5025
- }
5026
- /**
5027
- * Get current detector options.
5028
- *
5029
- * @returns Current detector options
5030
- */
5031
- getOptions() {
5032
- return {
5033
- ...this.options
5034
- };
5035
- }
5036
- // ===========================================================================
5037
- // Listener Management
5038
- // ===========================================================================
5039
- /**
5040
- * Add a listener for backend change events.
5041
- *
5042
- * @param listener - Callback to invoke when detection result changes
5043
- * @returns Function to remove the listener
5044
- */
5045
- addListener(listener) {
5046
- this.listeners.add(listener);
5047
- return () => this.listeners.delete(listener);
5048
- }
5049
- /**
5050
- * Remove a listener for backend change events.
5051
- *
5052
- * @param listener - Listener to remove
5053
- */
5054
- removeListener(listener) {
5055
- this.listeners.delete(listener);
5056
- }
5057
- /**
5058
- * Get the last detection result.
5059
- *
5060
- * @returns Last detection result or null if never detected
5061
- */
5062
- getLastResult() {
5063
- return this.lastResult;
5064
- }
5065
- // ===========================================================================
5066
- // Private Helper Methods
5067
- // ===========================================================================
5068
- /**
5069
- * Check if the detection result has changed from the last result.
5070
- */
5071
- hasResultChanged(result) {
5072
- if (!this.lastResult) {
5073
- return true;
5074
- }
5075
- return this.lastResult.powerSyncStatus !== result.powerSyncStatus || this.lastResult.supabaseStatus !== result.supabaseStatus || this.lastResult.recommendedBackend !== result.recommendedBackend || this.lastResult.isOnline !== result.isOnline;
5076
- }
5077
- /**
5078
- * Notify all listeners of a detection result change.
5079
- */
5080
- notifyListeners(result) {
5081
- const isDev = typeof __DEV__ !== "undefined" ? __DEV__ : process.env.NODE_ENV !== "production";
5082
- if (isDev) {
5083
- const prevBackend = this.lastResult?.recommendedBackend;
5084
- if (prevBackend && prevBackend !== result.recommendedBackend) {
5085
- console.log(`[DataLayer] Backend switched: ${prevBackend} \u2192 ${result.recommendedBackend}`, `| Reason: ${result.reason}`);
5086
- }
5087
- if (result.recommendedBackend === "supabase" && this.options.preferPowerSync) {
5088
- console.log(`[DataLayer] Using online fallback (Supabase)`, `| PowerSync: ${result.powerSyncStatus}`, `| Online: ${result.isOnline}`, `| Reason: ${result.reason}`);
5089
- }
5090
- }
5091
- Array.from(this.listeners).forEach((listener) => {
5092
- try {
5093
- listener(result);
5094
- } catch (error) {
5095
- console.error("Error in backend change listener:", error);
5096
- }
5097
- });
5098
- }
5099
- };
5100
- function createAdapterAutoDetector(powerSyncDb, supabase, options) {
5101
- return new AdapterAutoDetector(powerSyncDb, supabase, options);
5102
- }
5103
-
5104
4784
  // src/query/supabase-utils.ts
5105
4785
  var DEFAULT_SCHEMA = "public";
5106
4786
  function parseTableIdentifier(table) {
@@ -8204,11 +7884,10 @@ export {
8204
7884
  ADAPTER_STRATEGIES,
8205
7885
  SyncTrackingAdapter,
8206
7886
  stripSchemaPrefix,
7887
+ generatePowerSyncAlias,
7888
+ getPowerSyncAlias,
8207
7889
  AdapterRegistry,
8208
7890
  createAdapterRegistry,
8209
- BackendStatus,
8210
- AdapterAutoDetector,
8211
- createAdapterAutoDetector,
8212
7891
  SupabaseAdapter,
8213
7892
  createSupabaseAdapter,
8214
7893
  getErrorBody,
@@ -8265,4 +7944,4 @@ moment/moment.js:
8265
7944
  (*! license : MIT *)
8266
7945
  (*! momentjs.com *)
8267
7946
  */
8268
- //# sourceMappingURL=chunk-LG3OHLGB.js.map
7947
+ //# sourceMappingURL=chunk-VADZSRHY.js.map