@pol-studios/db 1.0.47 → 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.
Files changed (53) hide show
  1. package/dist/{DataLayerContext-DWlohoEg.d.ts → DataLayerContext--jqUiEMX.d.ts} +39 -2
  2. package/dist/auth/context.js +3 -3
  3. package/dist/auth/hooks.js +4 -4
  4. package/dist/auth/index.js +4 -4
  5. package/dist/chunk-CTRY7JDP.js +4112 -0
  6. package/dist/chunk-CTRY7JDP.js.map +1 -0
  7. package/dist/{chunk-5TWB3SMJ.js → chunk-DKUF2FKB.js} +2 -2
  8. package/dist/{chunk-UCXYYGFG.js → chunk-FLGHJCW3.js} +2 -2
  9. package/dist/{chunk-HJXJIBXC.js → chunk-GAJHPZ6N.js} +14 -11
  10. package/dist/chunk-GAJHPZ6N.js.map +1 -0
  11. package/dist/{chunk-POU4MVXN.js → chunk-GY7HDOBA.js} +3 -3
  12. package/dist/chunk-INEUG6MC.js +521 -0
  13. package/dist/chunk-INEUG6MC.js.map +1 -0
  14. package/dist/{chunk-LF3V3ERS.js → chunk-OKYHI6JG.js} +3 -3
  15. package/dist/{chunk-AKIRHA4Q.js → chunk-UJWETW36.js} +418 -527
  16. package/dist/chunk-UJWETW36.js.map +1 -0
  17. package/dist/{chunk-5KZ5ZB7B.js → chunk-V4MNSMMA.js} +70 -13
  18. package/dist/chunk-V4MNSMMA.js.map +1 -0
  19. package/dist/{chunk-FI6JAD5G.js → chunk-YA6MUTA7.js} +3 -3
  20. package/dist/{chunk-Z456IHCB.js → chunk-Z3EJX3VG.js} +3 -3
  21. package/dist/{chunk-WM25QE7E.js → chunk-ZGQ7Q4ZU.js} +2 -2
  22. package/dist/hooks/index.d.ts +2 -2
  23. package/dist/{index-CvAHE2Y2.d.ts → index-CJ8GAb_-.d.ts} +1 -1
  24. package/dist/index.d.ts +4 -4
  25. package/dist/index.js +11 -11
  26. package/dist/index.native.d.ts +5 -5
  27. package/dist/index.native.js +11 -11
  28. package/dist/index.web.d.ts +6 -6
  29. package/dist/index.web.js +11 -11
  30. package/dist/mutation/index.js +3 -3
  31. package/dist/parser/index.js +3 -3
  32. package/dist/query/index.js +4 -4
  33. package/dist/realtime/index.js +3 -3
  34. package/dist/types/index.d.ts +2 -2
  35. package/dist/types/index.js +4 -4
  36. package/dist/{useDbCount-Chl9uuR1.d.ts → useDbCount-DeXtNH0E.d.ts} +1 -1
  37. package/dist/{useResolveFeedback-lNxMVfUw.d.ts → useResolveFeedback-HTdDM4AQ.d.ts} +3 -3
  38. package/dist/with-auth/index.js +5 -5
  39. package/package.json +1 -1
  40. package/dist/chunk-5KZ5ZB7B.js.map +0 -1
  41. package/dist/chunk-AKIRHA4Q.js.map +0 -1
  42. package/dist/chunk-HJXJIBXC.js.map +0 -1
  43. package/dist/chunk-JOULSXOI.js +0 -415
  44. package/dist/chunk-JOULSXOI.js.map +0 -1
  45. package/dist/chunk-YUX6RGLZ.js +0 -1858
  46. package/dist/chunk-YUX6RGLZ.js.map +0 -1
  47. /package/dist/{chunk-5TWB3SMJ.js.map → chunk-DKUF2FKB.js.map} +0 -0
  48. /package/dist/{chunk-UCXYYGFG.js.map → chunk-FLGHJCW3.js.map} +0 -0
  49. /package/dist/{chunk-POU4MVXN.js.map → chunk-GY7HDOBA.js.map} +0 -0
  50. /package/dist/{chunk-LF3V3ERS.js.map → chunk-OKYHI6JG.js.map} +0 -0
  51. /package/dist/{chunk-FI6JAD5G.js.map → chunk-YA6MUTA7.js.map} +0 -0
  52. /package/dist/{chunk-Z456IHCB.js.map → chunk-Z3EJX3VG.js.map} +0 -0
  53. /package/dist/{chunk-WM25QE7E.js.map → chunk-ZGQ7Q4ZU.js.map} +0 -0
@@ -3,13 +3,13 @@ import {
3
3
  } from "./chunk-RJIVXO4U.js";
4
4
  import {
5
5
  normalizeFilter
6
- } from "./chunk-Z456IHCB.js";
6
+ } from "./chunk-Z3EJX3VG.js";
7
7
  import {
8
8
  OperationLog
9
9
  } from "./chunk-7SCJNYTE.js";
10
10
  import {
11
11
  useDbQuery
12
- } from "./chunk-5TWB3SMJ.js";
12
+ } from "./chunk-DKUF2FKB.js";
13
13
  import {
14
14
  useDataLayerCoreOptional
15
15
  } from "./chunk-AIYPSXIO.js";
@@ -18,7 +18,7 @@ import {
18
18
  } from "./chunk-GC3TBUWE.js";
19
19
  import {
20
20
  PostgrestParser
21
- } from "./chunk-JOULSXOI.js";
21
+ } from "./chunk-UJWETW36.js";
22
22
  import {
23
23
  buildNormalizedQuery,
24
24
  encode,
@@ -28,7 +28,7 @@ import {
28
28
  useQueriesForTableLoader,
29
29
  useQuery,
30
30
  useUpsertItem
31
- } from "./chunk-YUX6RGLZ.js";
31
+ } from "./chunk-CTRY7JDP.js";
32
32
  import {
33
33
  UserSessionId,
34
34
  useSupabase
@@ -4164,6 +4164,18 @@ var AdapterAutoDetector = class {
4164
4164
  listeners = /* @__PURE__ */ new Set();
4165
4165
  lastResult = null;
4166
4166
  syncStatus = null;
4167
+ /**
4168
+ * Update the PowerSync database reference.
4169
+ * Called when PowerSync becomes available after initial construction.
4170
+ *
4171
+ * @param db - PowerSync database instance or null
4172
+ */
4173
+ setPowerSyncDb(db) {
4174
+ this.powerSyncDb = db;
4175
+ if (db) {
4176
+ this.detect();
4177
+ }
4178
+ }
4167
4179
  /**
4168
4180
  * Update the sync status from PowerSync.
4169
4181
  * Called when sync status changes to re-evaluate backend recommendation.
@@ -4611,9 +4623,19 @@ var AdapterRegistry = class {
4611
4623
  */
4612
4624
  adapters = /* @__PURE__ */ new Map();
4613
4625
  /**
4614
- * PowerSync adapter instance (set during initialization)
4626
+ * PowerSync adapter instance (set during initialization or lazily via getter)
4615
4627
  */
4616
4628
  powerSyncAdapter = null;
4629
+ /**
4630
+ * Getter function to retrieve PowerSync database instance.
4631
+ * Used for lazy initialization when PowerSync becomes available after registry creation.
4632
+ */
4633
+ powerSyncGetter = null;
4634
+ /**
4635
+ * Factory function to create PowerSync adapter from database instance.
4636
+ * Set via setPowerSyncGetter along with the getter.
4637
+ */
4638
+ powerSyncAdapterFactory = null;
4617
4639
  /**
4618
4640
  * Supabase adapter instance (set during initialization)
4619
4641
  */
@@ -4682,6 +4704,46 @@ var AdapterRegistry = class {
4682
4704
  this.syncTrackingAdapter = null;
4683
4705
  }
4684
4706
  }
4707
+ /**
4708
+ * Set a getter function for lazy PowerSync adapter initialization.
4709
+ *
4710
+ * This allows the registry to lazily create the PowerSync adapter when
4711
+ * PowerSync becomes available, rather than requiring it at initialization time.
4712
+ * Solves race conditions where queries/mutations run before PowerSync is ready.
4713
+ *
4714
+ * @param getter - Function that returns the PowerSync database instance (or null if not ready)
4715
+ * @param factory - Function that creates a TableDataAdapter from the database instance
4716
+ */
4717
+ setPowerSyncGetter(getter, factory) {
4718
+ this.powerSyncGetter = getter;
4719
+ this.powerSyncAdapterFactory = factory;
4720
+ }
4721
+ /**
4722
+ * Ensure PowerSync adapter is initialized if available.
4723
+ *
4724
+ * Checks the getter (if set) and lazily creates the adapter if PowerSync
4725
+ * is now available. Also updates the auto-detector with the new reference.
4726
+ *
4727
+ * @returns true if PowerSync adapter is available, false otherwise
4728
+ */
4729
+ ensurePowerSyncAdapter() {
4730
+ if (this.powerSyncAdapter) {
4731
+ return true;
4732
+ }
4733
+ if (!this.powerSyncGetter || !this.powerSyncAdapterFactory) {
4734
+ return false;
4735
+ }
4736
+ const db = this.powerSyncGetter();
4737
+ if (!db) {
4738
+ return false;
4739
+ }
4740
+ const adapter = this.powerSyncAdapterFactory(db);
4741
+ this.setPowerSyncAdapter(adapter);
4742
+ if (this.autoDetector) {
4743
+ this.autoDetector.setPowerSyncDb(db);
4744
+ }
4745
+ return true;
4746
+ }
4685
4747
  /**
4686
4748
  * Set the sync tracker for mutation tracking.
4687
4749
  * When set, write operations on PowerSync tables will
@@ -4752,7 +4814,8 @@ var AdapterRegistry = class {
4752
4814
  * @returns The appropriate adapter for the table
4753
4815
  * @throws Error if adapters are not initialized
4754
4816
  */
4755
- getAdapter(table, operation = "read") {
4817
+ getAdapter(table, _operation = "read") {
4818
+ this.ensurePowerSyncAdapter();
4756
4819
  const tableWithoutSchema = table.includes(".") ? table.split(".")[1] : table;
4757
4820
  const strategy = this.config.tables[table] ?? this.config.tables[tableWithoutSchema];
4758
4821
  if (!strategy || strategy.strategy === "auto") {
@@ -4769,12 +4832,6 @@ var AdapterRegistry = class {
4769
4832
  return this.getAutoAdapter(strategy);
4770
4833
  }
4771
4834
  if (strategy.strategy === "powersync" && this.autoDetector && this.supabaseAdapter) {
4772
- if (operation === "write") {
4773
- if (this.powerSyncAdapter) {
4774
- return this.syncTrackingAdapter ?? this.powerSyncAdapter;
4775
- }
4776
- throw new Error(`PowerSync adapter not initialized for write operation on table "${table}". Writes to PowerSync tables require PowerSync to be available.`);
4777
- }
4778
4835
  const detection = this.autoDetector.detectSilent();
4779
4836
  if (detection.powerSyncStatus === "initializing" /* INITIALIZING */ && detection.isOnline) {
4780
4837
  return this.supabaseAdapter;
@@ -7930,4 +7987,4 @@ moment/moment.js:
7930
7987
  (*! license : MIT *)
7931
7988
  (*! momentjs.com *)
7932
7989
  */
7933
- //# sourceMappingURL=chunk-5KZ5ZB7B.js.map
7990
+ //# sourceMappingURL=chunk-V4MNSMMA.js.map