@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.
- package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapp-89f0ba.index.umd.js +1867 -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-2530150.index.umd.js +555 -0
- package/dist/_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapps_wa-sqlite_src_example-2530150.index.umd.js.map +1 -0
- package/dist/_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapps_wa-sqlite_src_example-2530151.index.umd.js +555 -0
- package/dist/_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapps_wa-sqlite_src_example-2530151.index.umd.js.map +1 -0
- package/dist/index.umd.js +5022 -38504
- package/dist/index.umd.js.map +1 -1
- package/dist/worker/SharedSyncImplementation.umd.js +819 -2220
- package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
- package/dist/worker/WASQLiteDB.umd.js +524 -2121
- package/dist/worker/WASQLiteDB.umd.js.map +1 -1
- 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
- package/dist/worker/node_modules_pnpm_bson_6_10_4_node_modules_bson_lib_bson_mjs.umd.js.map +1 -0
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/lib/package.json +27 -23
- package/lib/src/db/NavigatorTriggerClaimManager.d.ts +6 -0
- package/lib/src/db/NavigatorTriggerClaimManager.js +20 -0
- package/lib/src/db/PowerSyncDatabase.d.ts +5 -2
- package/lib/src/db/PowerSyncDatabase.js +49 -11
- 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 -1
- package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.d.ts +21 -4
- package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.js +116 -22
- package/lib/src/db/adapters/WebDBAdapter.d.ts +5 -2
- package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.d.ts +7 -3
- package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.js +14 -7
- package/lib/src/db/adapters/wa-sqlite/InternalWASQLiteDBAdapter.d.ts +12 -0
- package/lib/src/db/adapters/wa-sqlite/InternalWASQLiteDBAdapter.js +19 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.d.ts +2 -2
- package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js +11 -2
- package/lib/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.d.ts +4 -4
- package/lib/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.js +6 -6
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +5 -5
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +7 -7
- 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 +6 -9
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js +54 -38
- 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 +3 -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 +21 -11
- package/lib/src/worker/sync/SharedSyncImplementation.js +209 -113
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js +3 -3
- package/lib/src/worker/sync/WorkerClient.d.ts +4 -5
- package/lib/src/worker/sync/WorkerClient.js +8 -10
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +23 -19
- package/src/db/NavigatorTriggerClaimManager.ts +23 -0
- package/src/db/PowerSyncDatabase.ts +64 -22
- package/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.ts +1 -1
- package/src/db/adapters/AbstractWebSQLOpenFactory.ts +3 -3
- package/src/db/adapters/AsyncDatabaseConnection.ts +1 -1
- package/src/db/adapters/LockedAsyncDatabaseAdapter.ts +138 -33
- package/src/db/adapters/WebDBAdapter.ts +6 -2
- package/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.ts +20 -8
- package/src/db/adapters/wa-sqlite/InternalWASQLiteDBAdapter.ts +23 -0
- package/src/db/adapters/wa-sqlite/WASQLiteConnection.ts +13 -5
- package/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.ts +8 -8
- package/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.ts +9 -9
- package/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.ts +3 -3
- package/src/db/sync/SharedWebStreamingSyncImplementation.ts +69 -51
- 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 +5 -6
- 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 +241 -126
- package/src/worker/sync/SharedSyncImplementation.worker.ts +3 -3
- package/src/worker/sync/WorkerClient.ts +10 -14
- package/dist/worker/node_modules_bson_lib_bson_mjs.umd.js.map +0 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite-async_mjs.umd.js +0 -44
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite-async_mjs.umd.js.map +0 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite_mjs.umd.js +0 -44
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite_mjs.umd.js.map +0 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite-async_mjs.umd.js +0 -44
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite-async_mjs.umd.js.map +0 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js +0 -44
- package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js.map +0 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js.umd.js.map +0 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js.umd.js.map +0 -1
- package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_OPFSCoopSyncVFS_js.umd.js.map +0 -1
- /package/bin/{powersync.js → powersync.cjs} +0 -0
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as SQLite from '@journeyapps/wa-sqlite';
|
|
2
2
|
import { BaseObserver, BatchedUpdateNotification } from '@powersync/common';
|
|
3
3
|
import { Mutex } from 'async-mutex';
|
|
4
|
-
import { AsyncDatabaseConnection, OnTableChangeCallback, ProxiedQueryResult } from '../AsyncDatabaseConnection';
|
|
5
|
-
import { ResolvedWASQLiteOpenFactoryOptions } from './WASQLiteOpenFactory';
|
|
6
|
-
|
|
4
|
+
import { AsyncDatabaseConnection, OnTableChangeCallback, ProxiedQueryResult } from '../AsyncDatabaseConnection.js';
|
|
5
|
+
import { ResolvedWASQLiteOpenFactoryOptions } from './WASQLiteOpenFactory.js';
|
|
7
6
|
/**
|
|
8
7
|
* List of currently tested virtual filesystems
|
|
9
8
|
*/
|
|
@@ -126,9 +125,10 @@ export const DEFAULT_MODULE_FACTORIES = {
|
|
|
126
125
|
}
|
|
127
126
|
// @ts-expect-error The types for this static method are missing upstream
|
|
128
127
|
const { OPFSCoopSyncVFS } = await import('@journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js');
|
|
128
|
+
const vfs = await OPFSCoopSyncVFS.create(options.dbFileName, module);
|
|
129
129
|
return {
|
|
130
130
|
module,
|
|
131
|
-
vfs
|
|
131
|
+
vfs
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
134
|
};
|
|
@@ -387,7 +387,15 @@ export class WASqliteConnection
|
|
|
387
387
|
|
|
388
388
|
async close() {
|
|
389
389
|
this.broadcastChannel?.close();
|
|
390
|
-
await this.
|
|
390
|
+
await this.acquireExecuteLock(async () => {
|
|
391
|
+
/**
|
|
392
|
+
* Running the close operation inside the same execute mutex prevents errors like:
|
|
393
|
+
* ```
|
|
394
|
+
* unable to close due to unfinalized statements or unfinished backups
|
|
395
|
+
* ```
|
|
396
|
+
*/
|
|
397
|
+
await this.sqliteAPI.close(this.dbP);
|
|
398
|
+
});
|
|
391
399
|
}
|
|
392
400
|
|
|
393
401
|
async registerOnTableChange(callback: OnTableChangeCallback) {
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { type PowerSyncOpenFactoryOptions } from '@powersync/common';
|
|
2
2
|
import * as Comlink from 'comlink';
|
|
3
|
-
import { resolveWebPowerSyncFlags } from '../../PowerSyncDatabase';
|
|
4
|
-
import { OpenAsyncDatabaseConnection } from '../AsyncDatabaseConnection';
|
|
5
|
-
import { LockedAsyncDatabaseAdapter } from '../LockedAsyncDatabaseAdapter';
|
|
3
|
+
import { resolveWebPowerSyncFlags } from '../../PowerSyncDatabase.js';
|
|
4
|
+
import { OpenAsyncDatabaseConnection } from '../AsyncDatabaseConnection.js';
|
|
6
5
|
import {
|
|
7
6
|
DEFAULT_CACHE_SIZE_KB,
|
|
8
7
|
ResolvedWebSQLOpenOptions,
|
|
9
8
|
TemporaryStorageOption,
|
|
10
9
|
WebSQLFlags
|
|
11
|
-
} from '../web-sql-flags';
|
|
12
|
-
import { WorkerWrappedAsyncDatabaseConnection } from '../WorkerWrappedAsyncDatabaseConnection';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
10
|
+
} from '../web-sql-flags.js';
|
|
11
|
+
import { WorkerWrappedAsyncDatabaseConnection } from '../WorkerWrappedAsyncDatabaseConnection.js';
|
|
12
|
+
import { InternalWASQLiteDBAdapter } from './InternalWASQLiteDBAdapter.js';
|
|
13
|
+
import { WASQLiteVFS } from './WASQLiteConnection.js';
|
|
14
|
+
import { WASQLiteOpenFactory } from './WASQLiteOpenFactory.js';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* These flags are the same as {@link WebSQLFlags}.
|
|
@@ -44,7 +44,7 @@ export interface WASQLiteDBAdapterOptions extends Omit<PowerSyncOpenFactoryOptio
|
|
|
44
44
|
/**
|
|
45
45
|
* Adapter for WA-SQLite SQLite connections.
|
|
46
46
|
*/
|
|
47
|
-
export class WASQLiteDBAdapter extends
|
|
47
|
+
export class WASQLiteDBAdapter extends InternalWASQLiteDBAdapter {
|
|
48
48
|
constructor(options: WASQLiteDBAdapterOptions) {
|
|
49
49
|
super({
|
|
50
50
|
name: options.dbFilename,
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { type ILogLevel
|
|
1
|
+
import { DBAdapter, type ILogLevel } from '@powersync/common';
|
|
2
2
|
import * as Comlink from 'comlink';
|
|
3
|
-
import { openWorkerDatabasePort, resolveWorkerDatabasePortFactory } from '../../../worker/db/open-worker-database';
|
|
4
|
-
import { AbstractWebSQLOpenFactory } from '../AbstractWebSQLOpenFactory';
|
|
5
|
-
import { AsyncDatabaseConnection, OpenAsyncDatabaseConnection } from '../AsyncDatabaseConnection';
|
|
6
|
-
import {
|
|
3
|
+
import { openWorkerDatabasePort, resolveWorkerDatabasePortFactory } from '../../../worker/db/open-worker-database.js';
|
|
4
|
+
import { AbstractWebSQLOpenFactory } from '../AbstractWebSQLOpenFactory.js';
|
|
5
|
+
import { AsyncDatabaseConnection, OpenAsyncDatabaseConnection } from '../AsyncDatabaseConnection.js';
|
|
6
|
+
import { WorkerWrappedAsyncDatabaseConnection } from '../WorkerWrappedAsyncDatabaseConnection.js';
|
|
7
7
|
import {
|
|
8
8
|
DEFAULT_CACHE_SIZE_KB,
|
|
9
9
|
ResolvedWebSQLOpenOptions,
|
|
10
10
|
TemporaryStorageOption,
|
|
11
11
|
WebSQLOpenFactoryOptions
|
|
12
|
-
} from '../web-sql-flags';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
12
|
+
} from '../web-sql-flags.js';
|
|
13
|
+
import { InternalWASQLiteDBAdapter } from './InternalWASQLiteDBAdapter.js';
|
|
14
|
+
import { WASQLiteVFS, WASqliteConnection } from './WASQLiteConnection.js';
|
|
15
15
|
|
|
16
16
|
export interface WASQLiteOpenFactoryOptions extends WebSQLOpenFactoryOptions {
|
|
17
17
|
vfs?: WASQLiteVFS;
|
|
@@ -41,7 +41,7 @@ export class WASQLiteOpenFactory extends AbstractWebSQLOpenFactory {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
protected openAdapter(): DBAdapter {
|
|
44
|
-
return new
|
|
44
|
+
return new InternalWASQLiteDBAdapter({
|
|
45
45
|
name: this.options.dbFilename,
|
|
46
46
|
openConnection: () => this.openConnection(),
|
|
47
47
|
debugMode: this.options.debugMode,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AbstractPowerSyncDatabase, DBAdapter, PowerSyncDatabaseOptions } from '@powersync/common';
|
|
2
|
-
import { PowerSyncDatabase } from '../../../db/PowerSyncDatabase';
|
|
3
|
-
import { AbstractWebPowerSyncDatabaseOpenFactory } from '../AbstractWebPowerSyncDatabaseOpenFactory';
|
|
4
|
-
import { WASQLiteOpenFactory } from './WASQLiteOpenFactory';
|
|
2
|
+
import { PowerSyncDatabase } from '../../../db/PowerSyncDatabase.js';
|
|
3
|
+
import { AbstractWebPowerSyncDatabaseOpenFactory } from '../AbstractWebPowerSyncDatabaseOpenFactory.js';
|
|
4
|
+
import { WASQLiteOpenFactory } from './WASQLiteOpenFactory.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @deprecated {@link PowerSyncDatabase} can now be constructed directly
|
|
@@ -2,20 +2,19 @@ import {
|
|
|
2
2
|
PowerSyncConnectionOptions,
|
|
3
3
|
PowerSyncCredentials,
|
|
4
4
|
SubscribedStream,
|
|
5
|
-
SyncStatus,
|
|
6
5
|
SyncStatusOptions
|
|
7
6
|
} from '@powersync/common';
|
|
8
7
|
import * as Comlink from 'comlink';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
8
|
+
import { getNavigatorLocks } from '../../shared/navigator.js';
|
|
9
|
+
import { AbstractSharedSyncClientProvider } from '../../worker/sync/AbstractSharedSyncClientProvider.js';
|
|
10
|
+
import { ManualSharedSyncPayload, SharedSyncClientEvent } from '../../worker/sync/SharedSyncImplementation.js';
|
|
11
|
+
import { WorkerClient } from '../../worker/sync/WorkerClient.js';
|
|
12
|
+
import { WebDBAdapter } from '../adapters/WebDBAdapter.js';
|
|
13
|
+
import { DEFAULT_CACHE_SIZE_KB, TemporaryStorageOption, resolveWebSQLFlags } from '../adapters/web-sql-flags.js';
|
|
13
14
|
import {
|
|
14
15
|
WebStreamingSyncImplementation,
|
|
15
16
|
WebStreamingSyncImplementationOptions
|
|
16
|
-
} from './WebStreamingSyncImplementation';
|
|
17
|
-
import { WorkerClient } from '../../worker/sync/WorkerClient';
|
|
18
|
-
import { getNavigatorLocks } from '../../shared/navigator';
|
|
17
|
+
} from './WebStreamingSyncImplementation.js';
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
20
|
* The shared worker will trigger methods on this side of the message port
|
|
@@ -146,7 +145,25 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
146
145
|
).port;
|
|
147
146
|
}
|
|
148
147
|
|
|
148
|
+
/**
|
|
149
|
+
* Pass along any sync status updates to this listener
|
|
150
|
+
*/
|
|
151
|
+
this.clientProvider = new SharedSyncClientProvider(
|
|
152
|
+
this.webOptions,
|
|
153
|
+
(status) => {
|
|
154
|
+
this.updateSyncStatus(status);
|
|
155
|
+
},
|
|
156
|
+
options.db
|
|
157
|
+
);
|
|
158
|
+
|
|
149
159
|
this.syncManager = Comlink.wrap<WorkerClient>(this.messagePort);
|
|
160
|
+
/**
|
|
161
|
+
* The sync worker will call this client provider when it needs
|
|
162
|
+
* to fetch credentials or upload data.
|
|
163
|
+
* This performs bi-directional method calling.
|
|
164
|
+
*/
|
|
165
|
+
Comlink.expose(this.clientProvider, this.messagePort);
|
|
166
|
+
|
|
150
167
|
this.syncManager.setLogLevel(this.logger.getLevel());
|
|
151
168
|
|
|
152
169
|
this.triggerCrudUpload = this.syncManager.triggerCrudUpload;
|
|
@@ -157,10 +174,49 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
157
174
|
* DB worker, but a port to the DB worker can be transferred to the
|
|
158
175
|
* sync worker.
|
|
159
176
|
*/
|
|
177
|
+
|
|
178
|
+
this.isInitialized = this._init();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
protected async _init() {
|
|
182
|
+
/**
|
|
183
|
+
* The general flow of initialization is:
|
|
184
|
+
* - The client requests a unique navigator lock.
|
|
185
|
+
* - Once the lock is acquired, we register the lock with the shared worker.
|
|
186
|
+
* - The shared worker can then request the same lock. The client has been closed if the shared worker can acquire the lock.
|
|
187
|
+
* - Once the shared worker knows the client's lock, we can guarentee that the shared worker will detect if the client has been closed.
|
|
188
|
+
* - This makes the client safe for the shared worker to use.
|
|
189
|
+
* - The client is only added to the SharedSyncImplementation once the lock has been registered.
|
|
190
|
+
* This ensures we don't ever keep track of dead clients (tabs that closed before the lock was registered).
|
|
191
|
+
* - The client side lock is held until the client is disposed.
|
|
192
|
+
* - We resolve the top-level promise after the lock has been registered with the shared worker.
|
|
193
|
+
* - The client sends the params to the shared worker after locks have been registered.
|
|
194
|
+
*/
|
|
195
|
+
await new Promise<void>((resolve) => {
|
|
196
|
+
// Request a random lock until this client is disposed. The name of the lock is sent to the shared worker, which
|
|
197
|
+
// will also attempt to acquire it. Since the lock is returned when the tab is closed, this allows the share worker
|
|
198
|
+
// to free resources associated with this tab.
|
|
199
|
+
// We take hold of this lock as soon-as-possible in order to cater for potentially closed tabs.
|
|
200
|
+
getNavigatorLocks().request(`tab-close-signal-${crypto.randomUUID()}`, async (lock) => {
|
|
201
|
+
if (this.abortOnClose.signal.aborted) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
// Awaiting here ensures the worker is waiting for the lock
|
|
205
|
+
await this.syncManager.addLockBasedCloseSignal(lock!.name);
|
|
206
|
+
|
|
207
|
+
// The lock has been registered, we can continue with the initialization
|
|
208
|
+
resolve();
|
|
209
|
+
|
|
210
|
+
await new Promise<void>((r) => {
|
|
211
|
+
this.abortOnClose.signal.onabort = () => r();
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
160
216
|
const { crudUploadThrottleMs, identifier, retryDelayMs } = this.options;
|
|
161
217
|
const flags = { ...this.webOptions.flags, workers: undefined };
|
|
162
218
|
|
|
163
|
-
|
|
219
|
+
await this.syncManager.setParams(
|
|
164
220
|
{
|
|
165
221
|
dbParams: this.dbAdapter.getConfiguration(),
|
|
166
222
|
streamOptions: {
|
|
@@ -170,39 +226,8 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
170
226
|
flags: flags
|
|
171
227
|
}
|
|
172
228
|
},
|
|
173
|
-
options.subscriptions
|
|
229
|
+
this.options.subscriptions
|
|
174
230
|
);
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Pass along any sync status updates to this listener
|
|
178
|
-
*/
|
|
179
|
-
this.clientProvider = new SharedSyncClientProvider(
|
|
180
|
-
this.webOptions,
|
|
181
|
-
(status) => {
|
|
182
|
-
this.iterateListeners((l) => this.updateSyncStatus(status));
|
|
183
|
-
},
|
|
184
|
-
options.db
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* The sync worker will call this client provider when it needs
|
|
189
|
-
* to fetch credentials or upload data.
|
|
190
|
-
* This performs bi-directional method calling.
|
|
191
|
-
*/
|
|
192
|
-
Comlink.expose(this.clientProvider, this.messagePort);
|
|
193
|
-
|
|
194
|
-
// Request a random lock until this client is disposed. The name of the lock is sent to the shared worker, which
|
|
195
|
-
// will also attempt to acquire it. Since the lock is returned when the tab is closed, this allows the share worker
|
|
196
|
-
// to free resources associated with this tab.
|
|
197
|
-
getNavigatorLocks().request(`tab-close-signal-${crypto.randomUUID()}`, async (lock) => {
|
|
198
|
-
if (!this.abortOnClose.signal.aborted) {
|
|
199
|
-
this.syncManager.addLockBasedCloseSignal(lock!.name);
|
|
200
|
-
|
|
201
|
-
await new Promise<void>((r) => {
|
|
202
|
-
this.abortOnClose.signal.onabort = () => r();
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
231
|
}
|
|
207
232
|
|
|
208
233
|
/**
|
|
@@ -231,8 +256,6 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
231
256
|
async dispose(): Promise<void> {
|
|
232
257
|
await this.waitForReady();
|
|
233
258
|
|
|
234
|
-
await super.dispose();
|
|
235
|
-
|
|
236
259
|
await new Promise<void>((resolve) => {
|
|
237
260
|
// Listen for the close acknowledgment from the worker
|
|
238
261
|
this.messagePort.addEventListener('message', (event) => {
|
|
@@ -249,6 +272,9 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
249
272
|
};
|
|
250
273
|
this.messagePort.postMessage(closeMessagePayload);
|
|
251
274
|
});
|
|
275
|
+
|
|
276
|
+
await super.dispose();
|
|
277
|
+
|
|
252
278
|
this.abortOnClose.abort();
|
|
253
279
|
|
|
254
280
|
// Release the proxy
|
|
@@ -263,12 +289,4 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
263
289
|
updateSubscriptions(subscriptions: SubscribedStream[]): void {
|
|
264
290
|
this.syncManager.updateSubscriptions(subscriptions);
|
|
265
291
|
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Used in tests to force a connection states
|
|
269
|
-
*/
|
|
270
|
-
private async _testUpdateStatus(status: SyncStatus) {
|
|
271
|
-
await this.isInitialized;
|
|
272
|
-
return this.syncManager._testUpdateAllStatuses(status.toJSON());
|
|
273
|
-
}
|
|
274
292
|
}
|
package/src/db/sync/WebRemote.ts
CHANGED
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
LockOptions,
|
|
5
5
|
LockType
|
|
6
6
|
} from '@powersync/common';
|
|
7
|
-
import { getNavigatorLocks } from '../../shared/navigator';
|
|
8
|
-
import { ResolvedWebSQLOpenOptions, WebSQLFlags } from '../adapters/web-sql-flags';
|
|
7
|
+
import { getNavigatorLocks } from '../../shared/navigator.js';
|
|
8
|
+
import { ResolvedWebSQLOpenOptions, WebSQLFlags } from '../adapters/web-sql-flags.js';
|
|
9
9
|
|
|
10
10
|
export interface WebStreamingSyncImplementationOptions extends AbstractStreamingSyncImplementationOptions {
|
|
11
11
|
flags?: WebSQLFlags;
|
package/src/index.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';
|
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
AsyncDatabaseConnection,
|
|
4
4
|
OnTableChangeCallback,
|
|
5
5
|
ProxiedQueryResult
|
|
6
|
-
} from '../../db/adapters/AsyncDatabaseConnection';
|
|
7
|
-
import { ResolvedWebSQLOpenOptions } from '../../db/adapters/web-sql-flags';
|
|
6
|
+
} from '../../db/adapters/AsyncDatabaseConnection.js';
|
|
7
|
+
import { ResolvedWebSQLOpenOptions } from '../../db/adapters/web-sql-flags.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Keeps track of open DB connections and the clients which
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
import '@journeyapps/wa-sqlite';
|
|
6
6
|
import { createBaseLogger, createLogger } from '@powersync/common';
|
|
7
7
|
import * as Comlink from 'comlink';
|
|
8
|
-
import { AsyncDatabaseConnection } from '../../db/adapters/AsyncDatabaseConnection';
|
|
9
|
-
import { WorkerDBOpenerOptions } from '../../db/adapters/wa-sqlite/WASQLiteOpenFactory';
|
|
10
|
-
import { getNavigatorLocks } from '../../shared/navigator';
|
|
11
|
-
import { SharedDBWorkerConnection, SharedWASQLiteConnection } from './SharedWASQLiteConnection';
|
|
12
|
-
import { WorkerWASQLiteConnection } from './WorkerWASQLiteConnection';
|
|
8
|
+
import { AsyncDatabaseConnection } from '../../db/adapters/AsyncDatabaseConnection.js';
|
|
9
|
+
import { WorkerDBOpenerOptions } from '../../db/adapters/wa-sqlite/WASQLiteOpenFactory.js';
|
|
10
|
+
import { getNavigatorLocks } from '../../shared/navigator.js';
|
|
11
|
+
import { SharedDBWorkerConnection, SharedWASQLiteConnection } from './SharedWASQLiteConnection.js';
|
|
12
|
+
import { WorkerWASQLiteConnection } from './WorkerWASQLiteConnection.js';
|
|
13
13
|
|
|
14
14
|
const baseLogger = createBaseLogger();
|
|
15
15
|
baseLogger.useDefaults();
|
|
@@ -17,7 +17,6 @@ const logger = createLogger('db-worker');
|
|
|
17
17
|
|
|
18
18
|
const DBMap = new Map<string, SharedDBWorkerConnection>();
|
|
19
19
|
const OPEN_DB_LOCK = 'open-wasqlite-db';
|
|
20
|
-
|
|
21
20
|
let nextClientId = 1;
|
|
22
21
|
|
|
23
22
|
const openDBShared = async (options: WorkerDBOpenerOptions): Promise<AsyncDatabaseConnection> => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Comlink from 'comlink';
|
|
2
|
-
import { OnTableChangeCallback } from '../../db/adapters/AsyncDatabaseConnection';
|
|
3
|
-
import { WASqliteConnection } from '../../db/adapters/wa-sqlite/WASQLiteConnection';
|
|
2
|
+
import { OnTableChangeCallback } from '../../db/adapters/AsyncDatabaseConnection.js';
|
|
3
|
+
import { WASqliteConnection } from '../../db/adapters/wa-sqlite/WASQLiteConnection.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* A Small proxy wrapper around the WASqliteConnection.
|
|
@@ -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
|
/**
|
|
6
6
|
* Opens a shared or dedicated worker which exposes opening of database connections
|