@powersync/web 0.0.0-dev-20251203144301 → 0.0.0-dev-20260112083235
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.
- package/README.md +1 -1
- package/dist/0b19af1befc07ce338dd.wasm +0 -0
- package/dist/2632c3bda9473da74fd5.wasm +0 -0
- package/dist/64f5351ba3784bfe2f3e.wasm +0 -0
- package/dist/9318ca94aac4d0fe0135.wasm +0 -0
- package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapp-89f0ba.index.umd.js +1875 -0
- package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapp-89f0ba.index.umd.js.map +1 -0
- package/dist/_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapps_wa-sqlite_src_example-685f6c0.index.umd.js +567 -0
- package/dist/_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapps_wa-sqlite_src_example-685f6c0.index.umd.js.map +1 -0
- package/dist/_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapps_wa-sqlite_src_example-685f6c1.index.umd.js +567 -0
- package/dist/_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapps_wa-sqlite_src_example-685f6c1.index.umd.js.map +1 -0
- package/dist/index.umd.js +7107 -4249
- package/dist/index.umd.js.map +1 -1
- package/dist/worker/SharedSyncImplementation.umd.js +337 -2101
- package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
- package/dist/worker/WASQLiteDB.umd.js +182 -1931
- package/dist/worker/WASQLiteDB.umd.js.map +1 -1
- package/dist/worker/node_modules_bson_lib_bson_mjs.umd.js +3 -3
- package/dist/worker/node_modules_bson_lib_bson_mjs.umd.js.map +1 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite-async_mjs.umd.js +22 -9
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite-async_mjs.umd.js.map +1 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite_mjs.umd.js +22 -9
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite_mjs.umd.js.map +1 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite-async_mjs.umd.js +22 -9
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite-async_mjs.umd.js.map +1 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js +22 -9
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js.map +1 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js.umd.js +1206 -3
- package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js.umd.js.map +1 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js.umd.js +1209 -6
- package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js.umd.js.map +1 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_OPFSCoopSyncVFS_js.umd.js +1820 -0
- package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_OPFSCoopSyncVFS_js.umd.js.map +1 -0
- package/lib/package.json +20 -15
- package/lib/src/db/PowerSyncDatabase.d.ts +3 -1
- package/lib/src/db/PowerSyncDatabase.js +19 -7
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.d.ts +1 -1
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js +1 -1
- package/lib/src/db/adapters/AbstractWebSQLOpenFactory.d.ts +2 -2
- package/lib/src/db/adapters/AbstractWebSQLOpenFactory.js +2 -2
- package/lib/src/db/adapters/AsyncDatabaseConnection.d.ts +1 -9
- package/lib/src/db/adapters/AsyncDatabaseConnection.js +1 -11
- package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.d.ts +3 -3
- package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.js +25 -12
- package/lib/src/db/adapters/WebDBAdapter.d.ts +1 -1
- package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.d.ts +2 -2
- package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.js +1 -2
- package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.d.ts +2 -2
- package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js +12 -3
- package/lib/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.d.ts +3 -3
- package/lib/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.js +5 -5
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +4 -4
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +6 -6
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.d.ts +1 -1
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js +3 -3
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.d.ts +4 -4
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js +5 -5
- package/lib/src/db/sync/WebRemote.js +1 -1
- package/lib/src/db/sync/WebStreamingSyncImplementation.d.ts +1 -1
- package/lib/src/db/sync/WebStreamingSyncImplementation.js +1 -1
- package/lib/src/index.d.ts +12 -12
- package/lib/src/index.js +12 -12
- package/lib/src/worker/db/SharedWASQLiteConnection.d.ts +2 -2
- package/lib/src/worker/db/WASQLiteDB.worker.js +4 -3
- package/lib/src/worker/db/WorkerWASQLiteConnection.d.ts +2 -2
- package/lib/src/worker/db/WorkerWASQLiteConnection.js +1 -1
- package/lib/src/worker/db/open-worker-database.d.ts +2 -2
- package/lib/src/worker/db/open-worker-database.js +1 -1
- package/lib/src/worker/sync/BroadcastLogger.d.ts +1 -1
- package/lib/src/worker/sync/SharedSyncImplementation.d.ts +4 -4
- package/lib/src/worker/sync/SharedSyncImplementation.js +84 -83
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js +2 -2
- package/lib/src/worker/sync/WorkerClient.d.ts +1 -1
- package/lib/src/worker/sync/WorkerClient.js +2 -2
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -16
- package/src/db/PowerSyncDatabase.ts +23 -8
- package/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.ts +1 -1
- package/src/db/adapters/AbstractWebSQLOpenFactory.ts +3 -3
- package/src/db/adapters/AsyncDatabaseConnection.ts +1 -13
- package/src/db/adapters/LockedAsyncDatabaseAdapter.ts +30 -14
- package/src/db/adapters/WebDBAdapter.ts +1 -1
- package/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.ts +3 -4
- package/src/db/adapters/wa-sqlite/WASQLiteConnection.ts +14 -5
- package/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.ts +7 -7
- package/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.ts +7 -7
- package/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.ts +3 -3
- package/src/db/sync/SharedWebStreamingSyncImplementation.ts +7 -7
- package/src/db/sync/WebRemote.ts +1 -1
- package/src/db/sync/WebStreamingSyncImplementation.ts +2 -2
- package/src/index.ts +12 -12
- package/src/worker/db/SharedWASQLiteConnection.ts +2 -2
- package/src/worker/db/WASQLiteDB.worker.ts +6 -5
- package/src/worker/db/WorkerWASQLiteConnection.ts +2 -2
- package/src/worker/db/open-worker-database.ts +2 -2
- package/src/worker/sync/BroadcastLogger.ts +1 -1
- package/src/worker/sync/SharedSyncImplementation.ts +92 -89
- package/src/worker/sync/SharedSyncImplementation.worker.ts +2 -2
- package/src/worker/sync/WorkerClient.ts +2 -2
- package/dist/1807036ae51c10ee4d23.wasm +0 -0
- package/dist/307d8ce2280e3bae09d5.wasm +0 -0
- package/dist/cd8b9e8f4c87bf81c169.wasm +0 -0
- package/dist/e797080f5ed0b5324166.wasm +0 -0
- package/lib/src/worker/db/opfs.d.ts +0 -96
- package/lib/src/worker/db/opfs.js +0 -582
- package/src/worker/db/opfs.ts +0 -623
- /package/bin/{powersync.js → powersync.cjs} +0 -0
|
@@ -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
|
package/lib/src/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export * from '@powersync/common';
|
|
2
|
-
export * from './db/adapters/
|
|
3
|
-
export * from './db/adapters/
|
|
4
|
-
export * from './db/adapters/
|
|
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/
|
|
3
|
-
export * from './db/adapters/
|
|
4
|
-
export * from './db/adapters/
|
|
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');
|
|
@@ -14,6 +14,7 @@ const DBMap = new Map();
|
|
|
14
14
|
const OPEN_DB_LOCK = 'open-wasqlite-db';
|
|
15
15
|
let nextClientId = 1;
|
|
16
16
|
const openDBShared = async (options) => {
|
|
17
|
+
// Prevent multiple simultaneous opens from causing race conditions
|
|
17
18
|
return getNavigatorLocks().request(OPEN_DB_LOCK, async () => {
|
|
18
19
|
const clientId = nextClientId++;
|
|
19
20
|
const { dbFilename, logLevel } = options;
|
|
@@ -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 '
|
|
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,10 +1,10 @@
|
|
|
1
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 { WorkerWrappedAsyncDatabaseConnection } from '../../db/adapters/WorkerWrappedAsyncDatabaseConnection';
|
|
6
|
-
import { ResolvedWebSQLOpenOptions } from '../../db/adapters/web-sql-flags';
|
|
7
|
-
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';
|
|
8
8
|
/**
|
|
9
9
|
* @internal
|
|
10
10
|
* Manual message events for shared sync clients
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { AbortOperation, BaseObserver, ConnectionManager, SqliteBucketStorage, SyncStatus, createLogger } from '@powersync/common';
|
|
2
2
|
import { Mutex } from 'async-mutex';
|
|
3
3
|
import * as Comlink from 'comlink';
|
|
4
|
-
import { WebRemote } from '../../db/sync/WebRemote';
|
|
5
|
-
import { WebStreamingSyncImplementation } from '../../db/sync/WebStreamingSyncImplementation';
|
|
6
|
-
import { LockedAsyncDatabaseAdapter } from '../../db/adapters/LockedAsyncDatabaseAdapter';
|
|
7
|
-
import { WorkerWrappedAsyncDatabaseConnection } from '../../db/adapters/WorkerWrappedAsyncDatabaseConnection';
|
|
8
|
-
import { BroadcastLogger } from './BroadcastLogger';
|
|
4
|
+
import { WebRemote } from '../../db/sync/WebRemote.js';
|
|
5
|
+
import { WebStreamingSyncImplementation } from '../../db/sync/WebStreamingSyncImplementation.js';
|
|
6
|
+
import { LockedAsyncDatabaseAdapter } from '../../db/adapters/LockedAsyncDatabaseAdapter.js';
|
|
7
|
+
import { WorkerWrappedAsyncDatabaseConnection } from '../../db/adapters/WorkerWrappedAsyncDatabaseConnection.js';
|
|
8
|
+
import { BroadcastLogger } from './BroadcastLogger.js';
|
|
9
9
|
/**
|
|
10
10
|
* @internal
|
|
11
11
|
* Manual message events for shared sync clients
|
|
@@ -106,7 +106,8 @@ export class SharedSyncImplementation extends BaseObserver {
|
|
|
106
106
|
*/
|
|
107
107
|
async getRandomWrappedPort() {
|
|
108
108
|
return await this.portMutex.runExclusive(() => {
|
|
109
|
-
|
|
109
|
+
const nonClosingPorts = this.ports.filter((p) => !p.isClosing);
|
|
110
|
+
return nonClosingPorts[Math.floor(Math.random() * nonClosingPorts.length)];
|
|
110
111
|
});
|
|
111
112
|
}
|
|
112
113
|
async waitForStatus(status) {
|
|
@@ -181,6 +182,14 @@ export class SharedSyncImplementation extends BaseObserver {
|
|
|
181
182
|
// We may have missed some table updates while the database was closed.
|
|
182
183
|
// We can poke the crud in case we missed any updates.
|
|
183
184
|
this.connectionManager.syncStreamImplementation?.triggerCrudUpload();
|
|
185
|
+
/**
|
|
186
|
+
* FIXME or IMPROVE ME
|
|
187
|
+
* The Rust client implementation stores sync state on the connection level.
|
|
188
|
+
* Reopening the database causes a state machine error which should cause the
|
|
189
|
+
* StreamingSyncImplementation to reconnect. It would be nicer if we could trigger
|
|
190
|
+
* this reconnect earlier.
|
|
191
|
+
* This reconnect is not required for IndexedDB.
|
|
192
|
+
*/
|
|
184
193
|
}
|
|
185
194
|
});
|
|
186
195
|
self.onerror = (event) => {
|
|
@@ -373,85 +382,77 @@ export class SharedSyncImplementation extends BaseObserver {
|
|
|
373
382
|
* Opens a worker wrapped database connection. Using the last connected client port.
|
|
374
383
|
*/
|
|
375
384
|
async openInternalDB() {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
if (index >= 0) {
|
|
397
|
-
client.closeListeners.splice(index, 1);
|
|
398
|
-
}
|
|
399
|
-
};
|
|
400
|
-
client.closeListeners.push(closeListener);
|
|
401
|
-
const workerPort = await withAbort({
|
|
402
|
-
action: () => client.clientProvider.getDBWorkerPort(),
|
|
403
|
-
signal: abortController.signal,
|
|
404
|
-
cleanupOnAbort: (port) => {
|
|
405
|
-
port.close();
|
|
406
|
-
}
|
|
407
|
-
}).catch((ex) => {
|
|
408
|
-
removeCloseListener();
|
|
409
|
-
throw ex;
|
|
410
|
-
});
|
|
411
|
-
const remote = Comlink.wrap(workerPort);
|
|
412
|
-
const identifier = this.syncParams.dbParams.dbFilename;
|
|
413
|
-
/**
|
|
414
|
-
* The open could fail if the tab is closed while we're busy opening the database.
|
|
415
|
-
* This operation is typically executed inside an exclusive portMutex lock.
|
|
416
|
-
* We typically execute the closeListeners using the portMutex in a different context.
|
|
417
|
-
* We can't rely on the closeListeners to abort the operation if the tab is closed.
|
|
418
|
-
*/
|
|
419
|
-
const db = await withAbort({
|
|
420
|
-
action: () => remote(this.syncParams.dbParams),
|
|
421
|
-
signal: abortController.signal,
|
|
422
|
-
cleanupOnAbort: (db) => {
|
|
423
|
-
db.close();
|
|
424
|
-
}
|
|
425
|
-
}).finally(() => {
|
|
426
|
-
// We can remove the close listener here since we no longer need it past this point.
|
|
427
|
-
removeCloseListener();
|
|
428
|
-
});
|
|
429
|
-
clearTimeout(timeout);
|
|
430
|
-
const wrapped = new WorkerWrappedAsyncDatabaseConnection({
|
|
431
|
-
remote,
|
|
432
|
-
baseConnection: db,
|
|
433
|
-
identifier,
|
|
434
|
-
// It's possible for this worker to outlive the client hosting the database for us. We need to be prepared for
|
|
435
|
-
// that and ensure pending requests are aborted when the tab is closed.
|
|
436
|
-
remoteCanCloseUnexpectedly: true
|
|
437
|
-
});
|
|
438
|
-
client.closeListeners.push(async () => {
|
|
439
|
-
this.logger.info('Aborting open connection because associated tab closed.');
|
|
440
|
-
/**
|
|
441
|
-
* Don't await this close operation. It might never resolve if the tab is closed.
|
|
442
|
-
* We mark the remote as closed first, this will reject any pending requests.
|
|
443
|
-
* We then call close. The close operation is configured to fire-and-forget, the main promise will reject immediately.
|
|
444
|
-
*/
|
|
445
|
-
wrapped.markRemoteClosed();
|
|
446
|
-
wrapped.close().catch((ex) => this.logger.warn('error closing database connection', ex));
|
|
447
|
-
});
|
|
448
|
-
return wrapped;
|
|
385
|
+
const client = await this.getRandomWrappedPort();
|
|
386
|
+
if (!client) {
|
|
387
|
+
// Should not really happen in practice
|
|
388
|
+
throw new Error(`Could not open DB connection since no client is connected.`);
|
|
389
|
+
}
|
|
390
|
+
// Fail-safe timeout for opening a database connection.
|
|
391
|
+
const timeout = setTimeout(() => {
|
|
392
|
+
abortController.abort();
|
|
393
|
+
}, 10_000);
|
|
394
|
+
/**
|
|
395
|
+
* Handle cases where the client might close while opening a connection.
|
|
396
|
+
*/
|
|
397
|
+
const abortController = new AbortController();
|
|
398
|
+
const closeListener = () => {
|
|
399
|
+
abortController.abort();
|
|
400
|
+
};
|
|
401
|
+
const removeCloseListener = () => {
|
|
402
|
+
const index = client.closeListeners.indexOf(closeListener);
|
|
403
|
+
if (index >= 0) {
|
|
404
|
+
client.closeListeners.splice(index, 1);
|
|
449
405
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
406
|
+
};
|
|
407
|
+
client.closeListeners.push(closeListener);
|
|
408
|
+
const workerPort = await withAbort({
|
|
409
|
+
action: () => client.clientProvider.getDBWorkerPort(),
|
|
410
|
+
signal: abortController.signal,
|
|
411
|
+
cleanupOnAbort: (port) => {
|
|
412
|
+
port.close();
|
|
453
413
|
}
|
|
454
|
-
}
|
|
414
|
+
}).catch((ex) => {
|
|
415
|
+
removeCloseListener();
|
|
416
|
+
throw ex;
|
|
417
|
+
});
|
|
418
|
+
const remote = Comlink.wrap(workerPort);
|
|
419
|
+
const identifier = this.syncParams.dbParams.dbFilename;
|
|
420
|
+
/**
|
|
421
|
+
* The open could fail if the tab is closed while we're busy opening the database.
|
|
422
|
+
* This operation is typically executed inside an exclusive portMutex lock.
|
|
423
|
+
* We typically execute the closeListeners using the portMutex in a different context.
|
|
424
|
+
* We can't rely on the closeListeners to abort the operation if the tab is closed.
|
|
425
|
+
*/
|
|
426
|
+
const db = await withAbort({
|
|
427
|
+
action: () => remote(this.syncParams.dbParams),
|
|
428
|
+
signal: abortController.signal,
|
|
429
|
+
cleanupOnAbort: (db) => {
|
|
430
|
+
db.close();
|
|
431
|
+
}
|
|
432
|
+
}).finally(() => {
|
|
433
|
+
// We can remove the close listener here since we no longer need it past this point.
|
|
434
|
+
removeCloseListener();
|
|
435
|
+
});
|
|
436
|
+
clearTimeout(timeout);
|
|
437
|
+
const wrapped = new WorkerWrappedAsyncDatabaseConnection({
|
|
438
|
+
remote,
|
|
439
|
+
baseConnection: db,
|
|
440
|
+
identifier,
|
|
441
|
+
// It's possible for this worker to outlive the client hosting the database for us. We need to be prepared for
|
|
442
|
+
// that and ensure pending requests are aborted when the tab is closed.
|
|
443
|
+
remoteCanCloseUnexpectedly: true
|
|
444
|
+
});
|
|
445
|
+
client.closeListeners.push(async () => {
|
|
446
|
+
this.logger.info('Aborting open connection because associated tab closed.');
|
|
447
|
+
/**
|
|
448
|
+
* Don't await this close operation. It might never resolve if the tab is closed.
|
|
449
|
+
* We mark the remote as closed first, this will reject any pending requests.
|
|
450
|
+
* We then call close. The close operation is configured to fire-and-forget, the main promise will reject immediately.
|
|
451
|
+
*/
|
|
452
|
+
wrapped.markRemoteClosed();
|
|
453
|
+
wrapped.close().catch((ex) => this.logger.warn('error closing database connection', ex));
|
|
454
|
+
});
|
|
455
|
+
return wrapped;
|
|
455
456
|
}
|
|
456
457
|
/**
|
|
457
458
|
* A method to update the all shared statuses for each
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createBaseLogger } from '@powersync/common';
|
|
2
|
-
import { SharedSyncImplementation } from './SharedSyncImplementation';
|
|
3
|
-
import { WorkerClient } from './WorkerClient';
|
|
2
|
+
import { SharedSyncImplementation } from './SharedSyncImplementation.js';
|
|
3
|
+
import { WorkerClient } from './WorkerClient.js';
|
|
4
4
|
const _self = self;
|
|
5
5
|
const logger = createBaseLogger();
|
|
6
6
|
logger.useDefaults();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ILogLevel, PowerSyncConnectionOptions, SubscribedStream } from '@powersync/common';
|
|
2
|
-
import { SharedSyncImplementation, SharedSyncInitOptions, WrappedSyncPort } from './SharedSyncImplementation';
|
|
2
|
+
import { SharedSyncImplementation, SharedSyncInitOptions, WrappedSyncPort } from './SharedSyncImplementation.js';
|
|
3
3
|
/**
|
|
4
4
|
* A client to the shared sync worker.
|
|
5
5
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Comlink from 'comlink';
|
|
2
|
-
import { getNavigatorLocks } from '../../shared/navigator';
|
|
3
|
-
import { SharedSyncClientEvent } from './SharedSyncImplementation';
|
|
2
|
+
import { getNavigatorLocks } from '../../shared/navigator.js';
|
|
3
|
+
import { SharedSyncClientEvent } from './SharedSyncImplementation.js';
|
|
4
4
|
/**
|
|
5
5
|
* A client to the shared sync worker.
|
|
6
6
|
*
|