@powersync/web 1.30.0 → 1.32.0

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 (112) hide show
  1. package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapp-89f0ba.index.umd.js +1867 -0
  2. package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapp-89f0ba.index.umd.js.map +1 -0
  3. package/dist/_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapps_wa-sqlite_src_example-2530150.index.umd.js +555 -0
  4. package/dist/_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapps_wa-sqlite_src_example-2530150.index.umd.js.map +1 -0
  5. package/dist/_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapps_wa-sqlite_src_example-2530151.index.umd.js +555 -0
  6. package/dist/_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapps_wa-sqlite_src_example-2530151.index.umd.js.map +1 -0
  7. package/dist/index.umd.js +5022 -38504
  8. package/dist/index.umd.js.map +1 -1
  9. package/dist/worker/SharedSyncImplementation.umd.js +819 -2220
  10. package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
  11. package/dist/worker/WASQLiteDB.umd.js +524 -2121
  12. package/dist/worker/WASQLiteDB.umd.js.map +1 -1
  13. package/dist/worker/{node_modules_bson_lib_bson_mjs.umd.js → node_modules_pnpm_bson_6_10_4_node_modules_bson_lib_bson_mjs.umd.js} +8 -8
  14. package/dist/worker/node_modules_pnpm_bson_6_10_4_node_modules_bson_lib_bson_mjs.umd.js.map +1 -0
  15. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-3a94cf.umd.js +44 -0
  16. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-3a94cf.umd.js.map +1 -0
  17. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-868779.umd.js +44 -0
  18. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-868779.umd.js.map +1 -0
  19. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-f60d0d.umd.js +44 -0
  20. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-f60d0d.umd.js.map +1 -0
  21. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js +44 -0
  22. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js.map +1 -0
  23. package/dist/worker/{node_modules_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js.umd.js → node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_src_examples-0d2437.umd.js} +32 -32
  24. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_src_examples-0d2437.umd.js.map +1 -0
  25. package/dist/worker/{node_modules_journeyapps_wa-sqlite_src_examples_OPFSCoopSyncVFS_js.umd.js → node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_src_examples-1d4e74.umd.js} +24 -24
  26. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_src_examples-1d4e74.umd.js.map +1 -0
  27. package/dist/worker/{node_modules_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js.umd.js → node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_src_examples-3622cf.umd.js} +24 -24
  28. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_4_1_node_modules_journeyapps_wa-sqlite_src_examples-3622cf.umd.js.map +1 -0
  29. package/lib/package.json +27 -23
  30. package/lib/src/db/NavigatorTriggerClaimManager.d.ts +6 -0
  31. package/lib/src/db/NavigatorTriggerClaimManager.js +20 -0
  32. package/lib/src/db/PowerSyncDatabase.d.ts +5 -2
  33. package/lib/src/db/PowerSyncDatabase.js +49 -11
  34. package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.d.ts +1 -1
  35. package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js +1 -1
  36. package/lib/src/db/adapters/AbstractWebSQLOpenFactory.d.ts +2 -2
  37. package/lib/src/db/adapters/AbstractWebSQLOpenFactory.js +2 -2
  38. package/lib/src/db/adapters/AsyncDatabaseConnection.d.ts +1 -1
  39. package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.d.ts +21 -4
  40. package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.js +116 -22
  41. package/lib/src/db/adapters/WebDBAdapter.d.ts +5 -2
  42. package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.d.ts +7 -3
  43. package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.js +14 -7
  44. package/lib/src/db/adapters/wa-sqlite/InternalWASQLiteDBAdapter.d.ts +12 -0
  45. package/lib/src/db/adapters/wa-sqlite/InternalWASQLiteDBAdapter.js +19 -0
  46. package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.d.ts +2 -2
  47. package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js +11 -2
  48. package/lib/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.d.ts +4 -4
  49. package/lib/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.js +6 -6
  50. package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +5 -5
  51. package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +7 -7
  52. package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.d.ts +1 -1
  53. package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js +3 -3
  54. package/lib/src/db/sync/SharedWebStreamingSyncImplementation.d.ts +6 -9
  55. package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js +54 -38
  56. package/lib/src/db/sync/WebRemote.js +1 -1
  57. package/lib/src/db/sync/WebStreamingSyncImplementation.d.ts +1 -1
  58. package/lib/src/db/sync/WebStreamingSyncImplementation.js +1 -1
  59. package/lib/src/index.d.ts +12 -12
  60. package/lib/src/index.js +12 -12
  61. package/lib/src/worker/db/SharedWASQLiteConnection.d.ts +2 -2
  62. package/lib/src/worker/db/WASQLiteDB.worker.js +3 -3
  63. package/lib/src/worker/db/WorkerWASQLiteConnection.d.ts +2 -2
  64. package/lib/src/worker/db/WorkerWASQLiteConnection.js +1 -1
  65. package/lib/src/worker/db/open-worker-database.d.ts +2 -2
  66. package/lib/src/worker/db/open-worker-database.js +1 -1
  67. package/lib/src/worker/sync/BroadcastLogger.d.ts +1 -1
  68. package/lib/src/worker/sync/SharedSyncImplementation.d.ts +21 -11
  69. package/lib/src/worker/sync/SharedSyncImplementation.js +209 -113
  70. package/lib/src/worker/sync/SharedSyncImplementation.worker.js +3 -3
  71. package/lib/src/worker/sync/WorkerClient.d.ts +4 -5
  72. package/lib/src/worker/sync/WorkerClient.js +8 -10
  73. package/lib/tsconfig.tsbuildinfo +1 -1
  74. package/package.json +23 -19
  75. package/src/db/NavigatorTriggerClaimManager.ts +23 -0
  76. package/src/db/PowerSyncDatabase.ts +64 -22
  77. package/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.ts +1 -1
  78. package/src/db/adapters/AbstractWebSQLOpenFactory.ts +3 -3
  79. package/src/db/adapters/AsyncDatabaseConnection.ts +1 -1
  80. package/src/db/adapters/LockedAsyncDatabaseAdapter.ts +138 -33
  81. package/src/db/adapters/WebDBAdapter.ts +6 -2
  82. package/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.ts +20 -8
  83. package/src/db/adapters/wa-sqlite/InternalWASQLiteDBAdapter.ts +23 -0
  84. package/src/db/adapters/wa-sqlite/WASQLiteConnection.ts +13 -5
  85. package/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.ts +8 -8
  86. package/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.ts +9 -9
  87. package/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.ts +3 -3
  88. package/src/db/sync/SharedWebStreamingSyncImplementation.ts +69 -51
  89. package/src/db/sync/WebRemote.ts +1 -1
  90. package/src/db/sync/WebStreamingSyncImplementation.ts +2 -2
  91. package/src/index.ts +12 -12
  92. package/src/worker/db/SharedWASQLiteConnection.ts +2 -2
  93. package/src/worker/db/WASQLiteDB.worker.ts +5 -6
  94. package/src/worker/db/WorkerWASQLiteConnection.ts +2 -2
  95. package/src/worker/db/open-worker-database.ts +2 -2
  96. package/src/worker/sync/BroadcastLogger.ts +1 -1
  97. package/src/worker/sync/SharedSyncImplementation.ts +241 -126
  98. package/src/worker/sync/SharedSyncImplementation.worker.ts +3 -3
  99. package/src/worker/sync/WorkerClient.ts +10 -14
  100. package/dist/worker/node_modules_bson_lib_bson_mjs.umd.js.map +0 -1
  101. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite-async_mjs.umd.js +0 -44
  102. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite-async_mjs.umd.js.map +0 -1
  103. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite_mjs.umd.js +0 -44
  104. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite_mjs.umd.js.map +0 -1
  105. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite-async_mjs.umd.js +0 -44
  106. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite-async_mjs.umd.js.map +0 -1
  107. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js +0 -44
  108. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js.map +0 -1
  109. package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js.umd.js.map +0 -1
  110. package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js.umd.js.map +0 -1
  111. package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_OPFSCoopSyncVFS_js.umd.js.map +0 -1
  112. /package/bin/{powersync.js → powersync.cjs} +0 -0
@@ -1,9 +1,9 @@
1
1
  import * as Comlink from 'comlink';
2
- import { AbstractSharedSyncClientProvider } from '../../worker/sync/AbstractSharedSyncClientProvider';
3
- import { SharedSyncClientEvent } from '../../worker/sync/SharedSyncImplementation';
4
- import { DEFAULT_CACHE_SIZE_KB, resolveWebSQLFlags, TemporaryStorageOption } from '../adapters/web-sql-flags';
5
- import { WebStreamingSyncImplementation } from './WebStreamingSyncImplementation';
6
- import { getNavigatorLocks } from '../../shared/navigator';
2
+ import { getNavigatorLocks } from '../../shared/navigator.js';
3
+ import { AbstractSharedSyncClientProvider } from '../../worker/sync/AbstractSharedSyncClientProvider.js';
4
+ import { SharedSyncClientEvent } from '../../worker/sync/SharedSyncImplementation.js';
5
+ import { DEFAULT_CACHE_SIZE_KB, TemporaryStorageOption, resolveWebSQLFlags } from '../adapters/web-sql-flags.js';
6
+ import { WebStreamingSyncImplementation } from './WebStreamingSyncImplementation.js';
7
7
  /**
8
8
  * The shared worker will trigger methods on this side of the message port
9
9
  * via this client provider.
@@ -119,7 +119,19 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
119
119
  type: 'module'
120
120
  }).port;
121
121
  }
122
+ /**
123
+ * Pass along any sync status updates to this listener
124
+ */
125
+ this.clientProvider = new SharedSyncClientProvider(this.webOptions, (status) => {
126
+ this.updateSyncStatus(status);
127
+ }, options.db);
122
128
  this.syncManager = Comlink.wrap(this.messagePort);
129
+ /**
130
+ * The sync worker will call this client provider when it needs
131
+ * to fetch credentials or upload data.
132
+ * This performs bi-directional method calling.
133
+ */
134
+ Comlink.expose(this.clientProvider, this.messagePort);
123
135
  this.syncManager.setLogLevel(this.logger.getLevel());
124
136
  this.triggerCrudUpload = this.syncManager.triggerCrudUpload;
125
137
  /**
@@ -128,9 +140,43 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
128
140
  * DB worker, but a port to the DB worker can be transferred to the
129
141
  * sync worker.
130
142
  */
143
+ this.isInitialized = this._init();
144
+ }
145
+ async _init() {
146
+ /**
147
+ * The general flow of initialization is:
148
+ * - The client requests a unique navigator lock.
149
+ * - Once the lock is acquired, we register the lock with the shared worker.
150
+ * - The shared worker can then request the same lock. The client has been closed if the shared worker can acquire the lock.
151
+ * - Once the shared worker knows the client's lock, we can guarentee that the shared worker will detect if the client has been closed.
152
+ * - This makes the client safe for the shared worker to use.
153
+ * - The client is only added to the SharedSyncImplementation once the lock has been registered.
154
+ * This ensures we don't ever keep track of dead clients (tabs that closed before the lock was registered).
155
+ * - The client side lock is held until the client is disposed.
156
+ * - We resolve the top-level promise after the lock has been registered with the shared worker.
157
+ * - The client sends the params to the shared worker after locks have been registered.
158
+ */
159
+ await new Promise((resolve) => {
160
+ // Request a random lock until this client is disposed. The name of the lock is sent to the shared worker, which
161
+ // will also attempt to acquire it. Since the lock is returned when the tab is closed, this allows the share worker
162
+ // to free resources associated with this tab.
163
+ // We take hold of this lock as soon-as-possible in order to cater for potentially closed tabs.
164
+ getNavigatorLocks().request(`tab-close-signal-${crypto.randomUUID()}`, async (lock) => {
165
+ if (this.abortOnClose.signal.aborted) {
166
+ return;
167
+ }
168
+ // Awaiting here ensures the worker is waiting for the lock
169
+ await this.syncManager.addLockBasedCloseSignal(lock.name);
170
+ // The lock has been registered, we can continue with the initialization
171
+ resolve();
172
+ await new Promise((r) => {
173
+ this.abortOnClose.signal.onabort = () => r();
174
+ });
175
+ });
176
+ });
131
177
  const { crudUploadThrottleMs, identifier, retryDelayMs } = this.options;
132
178
  const flags = { ...this.webOptions.flags, workers: undefined };
133
- this.isInitialized = this.syncManager.setParams({
179
+ await this.syncManager.setParams({
134
180
  dbParams: this.dbAdapter.getConfiguration(),
135
181
  streamOptions: {
136
182
  crudUploadThrottleMs,
@@ -138,30 +184,7 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
138
184
  retryDelayMs,
139
185
  flags: flags
140
186
  }
141
- }, options.subscriptions);
142
- /**
143
- * Pass along any sync status updates to this listener
144
- */
145
- this.clientProvider = new SharedSyncClientProvider(this.webOptions, (status) => {
146
- this.iterateListeners((l) => this.updateSyncStatus(status));
147
- }, options.db);
148
- /**
149
- * The sync worker will call this client provider when it needs
150
- * to fetch credentials or upload data.
151
- * This performs bi-directional method calling.
152
- */
153
- Comlink.expose(this.clientProvider, this.messagePort);
154
- // Request a random lock until this client is disposed. The name of the lock is sent to the shared worker, which
155
- // will also attempt to acquire it. Since the lock is returned when the tab is closed, this allows the share worker
156
- // to free resources associated with this tab.
157
- getNavigatorLocks().request(`tab-close-signal-${crypto.randomUUID()}`, async (lock) => {
158
- if (!this.abortOnClose.signal.aborted) {
159
- this.syncManager.addLockBasedCloseSignal(lock.name);
160
- await new Promise((r) => {
161
- this.abortOnClose.signal.onabort = () => r();
162
- });
163
- }
164
- });
187
+ }, this.options.subscriptions);
165
188
  }
166
189
  /**
167
190
  * Starts the sync process, this effectively acts as a call to
@@ -184,7 +207,6 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
184
207
  }
185
208
  async dispose() {
186
209
  await this.waitForReady();
187
- await super.dispose();
188
210
  await new Promise((resolve) => {
189
211
  // Listen for the close acknowledgment from the worker
190
212
  this.messagePort.addEventListener('message', (event) => {
@@ -200,6 +222,7 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
200
222
  };
201
223
  this.messagePort.postMessage(closeMessagePayload);
202
224
  });
225
+ await super.dispose();
203
226
  this.abortOnClose.abort();
204
227
  // Release the proxy
205
228
  this.syncManager[Comlink.releaseProxy]();
@@ -211,11 +234,4 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
211
234
  updateSubscriptions(subscriptions) {
212
235
  this.syncManager.updateSubscriptions(subscriptions);
213
236
  }
214
- /**
215
- * Used in tests to force a connection states
216
- */
217
- async _testUpdateStatus(status) {
218
- await this.isInitialized;
219
- return this.syncManager._testUpdateAllStatuses(status.toJSON());
220
- }
221
237
  }
@@ -1,5 +1,5 @@
1
1
  import { AbstractRemote, DEFAULT_REMOTE_LOGGER, FetchImplementationProvider } from '@powersync/common';
2
- import { getUserAgentInfo } from './userAgent';
2
+ import { getUserAgentInfo } from './userAgent.js';
3
3
  /*
4
4
  * Depends on browser's implementation of global fetch.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  import { AbstractStreamingSyncImplementation, AbstractStreamingSyncImplementationOptions, LockOptions } from '@powersync/common';
2
- import { ResolvedWebSQLOpenOptions, WebSQLFlags } from '../adapters/web-sql-flags';
2
+ import { ResolvedWebSQLOpenOptions, WebSQLFlags } from '../adapters/web-sql-flags.js';
3
3
  export interface WebStreamingSyncImplementationOptions extends AbstractStreamingSyncImplementationOptions {
4
4
  flags?: WebSQLFlags;
5
5
  sync?: {
@@ -1,5 +1,5 @@
1
1
  import { AbstractStreamingSyncImplementation, LockType } from '@powersync/common';
2
- import { getNavigatorLocks } from '../../shared/navigator';
2
+ import { getNavigatorLocks } from '../../shared/navigator.js';
3
3
  export class WebStreamingSyncImplementation extends AbstractStreamingSyncImplementation {
4
4
  constructor(options) {
5
5
  // Super will store and provide default values for options
@@ -1,13 +1,13 @@
1
1
  export * from '@powersync/common';
2
- export * from './db/adapters/AsyncDatabaseConnection';
3
- export * from './db/adapters/AbstractWebPowerSyncDatabaseOpenFactory';
4
- export * from './db/adapters/AbstractWebSQLOpenFactory';
5
- export * from './db/adapters/wa-sqlite/WASQLiteConnection';
6
- export * from './db/adapters/wa-sqlite/WASQLiteDBAdapter';
7
- export * from './db/adapters/wa-sqlite/WASQLiteOpenFactory';
8
- export * from './db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory';
9
- export * from './db/adapters/web-sql-flags';
10
- export * from './db/PowerSyncDatabase';
11
- export * from './db/sync/SharedWebStreamingSyncImplementation';
12
- export * from './db/sync/WebRemote';
13
- export * from './db/sync/WebStreamingSyncImplementation';
2
+ export * from './db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js';
3
+ export * from './db/adapters/AbstractWebSQLOpenFactory.js';
4
+ export * from './db/adapters/AsyncDatabaseConnection.js';
5
+ export * from './db/adapters/wa-sqlite/WASQLiteConnection.js';
6
+ export * from './db/adapters/wa-sqlite/WASQLiteDBAdapter.js';
7
+ export * from './db/adapters/wa-sqlite/WASQLiteOpenFactory.js';
8
+ export * from './db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js';
9
+ export * from './db/adapters/web-sql-flags.js';
10
+ export * from './db/PowerSyncDatabase.js';
11
+ export * from './db/sync/SharedWebStreamingSyncImplementation.js';
12
+ export * from './db/sync/WebRemote.js';
13
+ export * from './db/sync/WebStreamingSyncImplementation.js';
package/lib/src/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  export * from '@powersync/common';
2
- export * from './db/adapters/AsyncDatabaseConnection';
3
- export * from './db/adapters/AbstractWebPowerSyncDatabaseOpenFactory';
4
- export * from './db/adapters/AbstractWebSQLOpenFactory';
5
- export * from './db/adapters/wa-sqlite/WASQLiteConnection';
6
- export * from './db/adapters/wa-sqlite/WASQLiteDBAdapter';
7
- export * from './db/adapters/wa-sqlite/WASQLiteOpenFactory';
8
- export * from './db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory';
9
- export * from './db/adapters/web-sql-flags';
10
- export * from './db/PowerSyncDatabase';
11
- export * from './db/sync/SharedWebStreamingSyncImplementation';
12
- export * from './db/sync/WebRemote';
13
- export * from './db/sync/WebStreamingSyncImplementation';
2
+ export * from './db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js';
3
+ export * from './db/adapters/AbstractWebSQLOpenFactory.js';
4
+ export * from './db/adapters/AsyncDatabaseConnection.js';
5
+ export * from './db/adapters/wa-sqlite/WASQLiteConnection.js';
6
+ export * from './db/adapters/wa-sqlite/WASQLiteDBAdapter.js';
7
+ export * from './db/adapters/wa-sqlite/WASQLiteOpenFactory.js';
8
+ export * from './db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js';
9
+ export * from './db/adapters/web-sql-flags.js';
10
+ export * from './db/PowerSyncDatabase.js';
11
+ export * from './db/sync/SharedWebStreamingSyncImplementation.js';
12
+ export * from './db/sync/WebRemote.js';
13
+ export * from './db/sync/WebStreamingSyncImplementation.js';
@@ -1,6 +1,6 @@
1
1
  import { ILogger } from '@powersync/common';
2
- import { AsyncDatabaseConnection, OnTableChangeCallback, ProxiedQueryResult } from '../../db/adapters/AsyncDatabaseConnection';
3
- import { ResolvedWebSQLOpenOptions } from '../../db/adapters/web-sql-flags';
2
+ import { AsyncDatabaseConnection, OnTableChangeCallback, ProxiedQueryResult } from '../../db/adapters/AsyncDatabaseConnection.js';
3
+ import { ResolvedWebSQLOpenOptions } from '../../db/adapters/web-sql-flags.js';
4
4
  /**
5
5
  * Keeps track of open DB connections and the clients which
6
6
  * are using it.
@@ -4,9 +4,9 @@
4
4
  import '@journeyapps/wa-sqlite';
5
5
  import { createBaseLogger, createLogger } from '@powersync/common';
6
6
  import * as Comlink from 'comlink';
7
- import { getNavigatorLocks } from '../../shared/navigator';
8
- import { SharedWASQLiteConnection } from './SharedWASQLiteConnection';
9
- import { WorkerWASQLiteConnection } from './WorkerWASQLiteConnection';
7
+ import { getNavigatorLocks } from '../../shared/navigator.js';
8
+ import { SharedWASQLiteConnection } from './SharedWASQLiteConnection.js';
9
+ import { WorkerWASQLiteConnection } from './WorkerWASQLiteConnection.js';
10
10
  const baseLogger = createBaseLogger();
11
11
  baseLogger.useDefaults();
12
12
  const logger = createLogger('db-worker');
@@ -1,5 +1,5 @@
1
- import { OnTableChangeCallback } from '../../db/adapters/AsyncDatabaseConnection';
2
- import { WASqliteConnection } from '../../db/adapters/wa-sqlite/WASQLiteConnection';
1
+ import { OnTableChangeCallback } from '../../db/adapters/AsyncDatabaseConnection.js';
2
+ import { WASqliteConnection } from '../../db/adapters/wa-sqlite/WASQLiteConnection.js';
3
3
  /**
4
4
  * A Small proxy wrapper around the WASqliteConnection.
5
5
  * This ensures that certain return types are properly proxied.
@@ -1,5 +1,5 @@
1
1
  import * as Comlink from 'comlink';
2
- import { WASqliteConnection } from '../../db/adapters/wa-sqlite/WASQLiteConnection';
2
+ import { WASqliteConnection } from '../../db/adapters/wa-sqlite/WASQLiteConnection.js';
3
3
  /**
4
4
  * A Small proxy wrapper around the WASqliteConnection.
5
5
  * This ensures that certain return types are properly proxied.
@@ -1,6 +1,6 @@
1
1
  import * as Comlink from 'comlink';
2
- import { OpenAsyncDatabaseConnection } from '../..//db/adapters/AsyncDatabaseConnection';
3
- import { WASQLiteVFS } from '../../db/adapters/wa-sqlite/WASQLiteConnection';
2
+ import { OpenAsyncDatabaseConnection } from '../../db/adapters/AsyncDatabaseConnection.js';
3
+ import { WASQLiteVFS } from '../../db/adapters/wa-sqlite/WASQLiteConnection.js';
4
4
  /**
5
5
  * Opens a shared or dedicated worker which exposes opening of database connections
6
6
  */
@@ -1,5 +1,5 @@
1
1
  import * as Comlink from 'comlink';
2
- import { WASQLiteVFS } from '../../db/adapters/wa-sqlite/WASQLiteConnection';
2
+ import { WASQLiteVFS } from '../../db/adapters/wa-sqlite/WASQLiteConnection.js';
3
3
  /**
4
4
  * Opens a shared or dedicated worker which exposes opening of database connections
5
5
  */
@@ -1,5 +1,5 @@
1
1
  import { type ILogger, type ILogLevel } from '@powersync/common';
2
- import { type WrappedSyncPort } from './SharedSyncImplementation';
2
+ import { type WrappedSyncPort } from './SharedSyncImplementation.js';
3
3
  /**
4
4
  * Broadcasts logs to all clients
5
5
  */
@@ -1,9 +1,10 @@
1
- import { BaseObserver, ConnectionManager, DBAdapter, SubscribedStream, SyncStatus, type ILogger, type ILogLevel, type PowerSyncConnectionOptions, type StreamingSyncImplementation, type StreamingSyncImplementationListener, type SyncStatusOptions } from '@powersync/common';
1
+ import { BaseObserver, ConnectionManager, DBAdapter, SubscribedStream, SyncStatus, type ILogLevel, type ILogger, type PowerSyncConnectionOptions, type StreamingSyncImplementation, type StreamingSyncImplementationListener, type SyncStatusOptions } from '@powersync/common';
2
2
  import { Mutex } from 'async-mutex';
3
3
  import * as Comlink from 'comlink';
4
- import { WebStreamingSyncImplementation, WebStreamingSyncImplementationOptions } from '../../db/sync/WebStreamingSyncImplementation';
5
- import { ResolvedWebSQLOpenOptions } from '../../db/adapters/web-sql-flags';
6
- import { AbstractSharedSyncClientProvider } from './AbstractSharedSyncClientProvider';
4
+ import { WebStreamingSyncImplementation, WebStreamingSyncImplementationOptions } from '../../db/sync/WebStreamingSyncImplementation.js';
5
+ import { WorkerWrappedAsyncDatabaseConnection } from '../../db/adapters/WorkerWrappedAsyncDatabaseConnection.js';
6
+ import { ResolvedWebSQLOpenOptions } from '../../db/adapters/web-sql-flags.js';
7
+ import { AbstractSharedSyncClientProvider } from './AbstractSharedSyncClientProvider.js';
7
8
  /**
8
9
  * @internal
9
10
  * Manual message events for shared sync clients
@@ -45,6 +46,7 @@ export type WrappedSyncPort = {
45
46
  db?: DBAdapter;
46
47
  currentSubscriptions: SubscribedStream[];
47
48
  closeListeners: (() => void | Promise<void>)[];
49
+ isClosing: boolean;
48
50
  };
49
51
  /**
50
52
  * @internal
@@ -63,7 +65,6 @@ export declare class SharedSyncImplementation extends BaseObserver<SharedSyncImp
63
65
  protected statusListener?: () => void;
64
66
  protected fetchCredentialsController?: RemoteOperationAbortController;
65
67
  protected uploadDataController?: RemoteOperationAbortController;
66
- protected dbAdapter: DBAdapter | null;
67
68
  protected syncParams: SharedSyncInitOptions | null;
68
69
  protected logger: ILogger;
69
70
  protected lastConnectOptions: PowerSyncConnectionOptions | undefined;
@@ -72,9 +73,19 @@ export declare class SharedSyncImplementation extends BaseObserver<SharedSyncImp
72
73
  protected connectionManager: ConnectionManager;
73
74
  syncStatus: SyncStatus;
74
75
  broadCastLogger: ILogger;
76
+ protected distributedDB: DBAdapter | null;
75
77
  constructor();
76
78
  get lastSyncedAt(): Date | undefined;
77
79
  get isConnected(): boolean;
80
+ /**
81
+ * Gets the last client port which we know is safe from unexpected closes.
82
+ */
83
+ protected getLastWrappedPort(): Promise<WrappedSyncPort | undefined>;
84
+ /**
85
+ * In some very rare cases a specific tab might not respond to requests.
86
+ * This returns a random port which is not closing.
87
+ */
88
+ protected getRandomWrappedPort(): Promise<WrappedSyncPort | undefined>;
78
89
  waitForStatus(status: SyncStatusOptions): Promise<void>;
79
90
  waitUntilStatusMatches(predicate: (status: SyncStatus) => boolean): Promise<void>;
80
91
  waitForReady(): Promise<void>;
@@ -102,6 +113,7 @@ export declare class SharedSyncImplementation extends BaseObserver<SharedSyncImp
102
113
  clientProvider: Comlink.Remote<AbstractSharedSyncClientProvider>;
103
114
  currentSubscriptions: never[];
104
115
  closeListeners: never[];
116
+ isClosing: false;
105
117
  }>;
106
118
  /**
107
119
  * Removes a message port client from this manager's managed
@@ -113,15 +125,13 @@ export declare class SharedSyncImplementation extends BaseObserver<SharedSyncImp
113
125
  getWriteCheckpoint(): Promise<string>;
114
126
  protected withSyncImplementation<T>(callback: (sync: StreamingSyncImplementation) => Promise<T>): Promise<T>;
115
127
  protected generateStreamingImplementation(): WebStreamingSyncImplementation;
116
- protected openInternalDB(): Promise<void>;
128
+ /**
129
+ * Opens a worker wrapped database connection. Using the last connected client port.
130
+ */
131
+ protected openInternalDB(): Promise<WorkerWrappedAsyncDatabaseConnection<ResolvedWebSQLOpenOptions>>;
117
132
  /**
118
133
  * A method to update the all shared statuses for each
119
134
  * client.
120
135
  */
121
136
  private updateAllStatuses;
122
- /**
123
- * A function only used for unit tests which updates the internal
124
- * sync stream client and all tab client's sync status
125
- */
126
- _testUpdateAllStatuses(status: SyncStatusOptions): Promise<void>;
127
137
  }