@powersync/web 0.0.0-dev-20260504100448 → 0.0.0-dev-20260630144038
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/bin/powersync.cjs +1 -1
- package/dist/index.react_native_web.js +1879 -0
- package/dist/index.react_native_web.js.map +1 -0
- package/dist/worker/AccessHandlePoolVFS-BPUHfZME.js +2 -0
- package/dist/worker/AccessHandlePoolVFS-BPUHfZME.js.map +1 -0
- package/dist/worker/FacadeVFS-d1ZDvud7.js +2 -0
- package/dist/worker/FacadeVFS-d1ZDvud7.js.map +1 -0
- package/dist/worker/IDBBatchAtomicVFS-DbkDb777.js +2 -0
- package/dist/worker/IDBBatchAtomicVFS-DbkDb777.js.map +1 -0
- package/dist/worker/OPFSCoopSyncVFS-DRKedN0p.js +2 -0
- package/dist/worker/OPFSCoopSyncVFS-DRKedN0p.js.map +1 -0
- package/dist/worker/OPFSWriteAheadVFS-BzodSqNq.js +2 -0
- package/dist/worker/OPFSWriteAheadVFS-BzodSqNq.js.map +1 -0
- package/dist/worker/mc-wa-sqlite-DiBqIVE5.js +2 -0
- package/dist/worker/mc-wa-sqlite-DiBqIVE5.js.map +1 -0
- package/dist/worker/mc-wa-sqlite-async-DUEhO9ef.js +2 -0
- package/dist/worker/mc-wa-sqlite-async-DUEhO9ef.js.map +1 -0
- package/dist/worker/wa-sqlite-BlSx7-_P.js +2 -0
- package/dist/worker/wa-sqlite-BlSx7-_P.js.map +1 -0
- package/dist/worker/wa-sqlite-async-BdR24Ucf.js +2 -0
- package/dist/worker/wa-sqlite-async-BdR24Ucf.js.map +1 -0
- package/dist/worker/websockets-Q8W_lerF.js +9 -0
- package/dist/worker/websockets-Q8W_lerF.js.map +1 -0
- package/dist/worker/worker.js +7 -0
- package/dist/worker/worker.js.map +1 -0
- package/lib/{src/attachments → attachments}/IndexDBFileSystemAdapter.js +1 -0
- package/lib/attachments/IndexDBFileSystemAdapter.js.map +1 -0
- package/lib/{src/db → db}/NavigatorTriggerClaimManager.d.ts +1 -1
- package/lib/{src/db → db}/NavigatorTriggerClaimManager.js +1 -0
- package/lib/db/NavigatorTriggerClaimManager.js.map +1 -0
- package/lib/db/PowerSyncDatabase.d.ts +67 -0
- package/lib/{src/db → db}/PowerSyncDatabase.js +48 -61
- package/lib/db/PowerSyncDatabase.js.map +1 -0
- package/lib/db/adapters/AsyncWebAdapter.d.ts +32 -0
- package/lib/{src/db → db}/adapters/AsyncWebAdapter.js +15 -14
- package/lib/db/adapters/AsyncWebAdapter.js.map +1 -0
- package/lib/db/adapters/SSRDBAdapter.d.ts +17 -0
- package/lib/db/adapters/SSRDBAdapter.js +37 -0
- package/lib/db/adapters/SSRDBAdapter.js.map +1 -0
- package/lib/{src/db → db}/adapters/WebDBAdapter.d.ts +1 -1
- package/lib/db/adapters/WebDBAdapter.js +2 -0
- package/lib/db/adapters/WebDBAdapter.js.map +1 -0
- package/lib/db/adapters/options.d.ts +87 -0
- package/lib/db/adapters/options.js +6 -0
- package/lib/db/adapters/options.js.map +1 -0
- package/lib/db/adapters/resolveAndValidateOptions.d.ts +5 -0
- package/lib/db/adapters/resolveAndValidateOptions.js +33 -0
- package/lib/db/adapters/resolveAndValidateOptions.js.map +1 -0
- package/lib/{src/db → db}/adapters/wa-sqlite/ConcurrentConnection.d.ts +3 -4
- package/lib/{src/db → db}/adapters/wa-sqlite/ConcurrentConnection.js +3 -2
- package/lib/db/adapters/wa-sqlite/ConcurrentConnection.js.map +1 -0
- package/lib/{src/db → db}/adapters/wa-sqlite/DatabaseClient.d.ts +4 -4
- package/lib/{src/db → db}/adapters/wa-sqlite/DatabaseClient.js +12 -37
- package/lib/db/adapters/wa-sqlite/DatabaseClient.js.map +1 -0
- package/lib/{src/db → db}/adapters/wa-sqlite/DatabaseServer.d.ts +5 -5
- package/lib/{src/db → db}/adapters/wa-sqlite/DatabaseServer.js +12 -7
- package/lib/db/adapters/wa-sqlite/DatabaseServer.js.map +1 -0
- package/lib/{src/db → db}/adapters/wa-sqlite/RawSqliteConnection.d.ts +22 -12
- package/lib/{src/db → db}/adapters/wa-sqlite/RawSqliteConnection.js +12 -10
- package/lib/db/adapters/wa-sqlite/RawSqliteConnection.js.map +1 -0
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +18 -0
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +131 -0
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.js.map +1 -0
- package/lib/{src/db → db}/adapters/wa-sqlite/vfs.js +1 -0
- package/lib/db/adapters/wa-sqlite/vfs.js.map +1 -0
- package/lib/{src/db → db}/sync/SSRWebStreamingSyncImplementation.d.ts +4 -8
- package/lib/{src/db → db}/sync/SSRWebStreamingSyncImplementation.js +5 -11
- package/lib/db/sync/SSRWebStreamingSyncImplementation.js.map +1 -0
- package/lib/{src/db → db}/sync/SharedWebStreamingSyncImplementation.d.ts +13 -14
- package/lib/{src/db → db}/sync/SharedWebStreamingSyncImplementation.js +32 -66
- package/lib/db/sync/SharedWebStreamingSyncImplementation.js.map +1 -0
- package/lib/db/sync/WebRemote.d.ts +10 -0
- package/lib/db/sync/WebRemote.js +33 -0
- package/lib/db/sync/WebRemote.js.map +1 -0
- package/lib/{src/db → db}/sync/WebStreamingSyncImplementation.d.ts +2 -4
- package/lib/{src/db → db}/sync/WebStreamingSyncImplementation.js +4 -2
- package/lib/db/sync/WebStreamingSyncImplementation.js.map +1 -0
- package/lib/{src/db → db}/sync/userAgent.js +1 -0
- package/lib/db/sync/userAgent.js.map +1 -0
- package/lib/{src/index.d.ts → index.d.ts} +1 -3
- package/lib/{src/index.js → index.js} +2 -3
- package/lib/index.js.map +1 -0
- package/lib/{src/shared → shared}/navigator.js +1 -0
- package/lib/shared/navigator.js.map +1 -0
- package/lib/{src/shared → shared}/tab_close_signal.js +1 -0
- package/lib/shared/tab_close_signal.js.map +1 -0
- package/lib/worker/SharedWorkerConnectionRequest.d.ts +5 -0
- package/lib/worker/SharedWorkerConnectionRequest.js +2 -0
- package/lib/worker/SharedWorkerConnectionRequest.js.map +1 -0
- package/lib/worker/client.d.ts +15 -0
- package/lib/worker/client.js +77 -0
- package/lib/worker/client.js.map +1 -0
- package/lib/worker/db/MultiDatabaseServer.d.ts +22 -0
- package/lib/{src/worker → worker}/db/MultiDatabaseServer.js +26 -15
- package/lib/worker/db/MultiDatabaseServer.js.map +1 -0
- package/lib/worker/sync/AbstractSharedSyncClientProvider.d.ts +13 -0
- package/lib/{src/worker → worker}/sync/AbstractSharedSyncClientProvider.js +1 -0
- package/lib/worker/sync/AbstractSharedSyncClientProvider.js.map +1 -0
- package/lib/worker/sync/BroadcastLogger.d.ts +27 -0
- package/lib/worker/sync/BroadcastLogger.js +65 -0
- package/lib/worker/sync/BroadcastLogger.js.map +1 -0
- package/lib/{src/worker → worker}/sync/SharedSyncImplementation.d.ts +11 -15
- package/lib/{src/worker → worker}/sync/SharedSyncImplementation.js +43 -43
- package/lib/worker/sync/SharedSyncImplementation.js.map +1 -0
- package/lib/{src/worker → worker}/sync/WorkerClient.d.ts +3 -3
- package/lib/{src/worker → worker}/sync/WorkerClient.js +3 -2
- package/lib/worker/sync/WorkerClient.js.map +1 -0
- package/lib/worker/worker.js +34 -0
- package/lib/worker/worker.js.map +1 -0
- package/package.json +22 -29
- package/src/db/NavigatorTriggerClaimManager.ts +1 -1
- package/src/db/PowerSyncDatabase.ts +80 -122
- package/src/db/adapters/AsyncWebAdapter.ts +17 -26
- package/src/db/adapters/SSRDBAdapter.ts +14 -64
- package/src/db/adapters/WebDBAdapter.ts +1 -1
- package/src/db/adapters/options.ts +100 -0
- package/src/db/adapters/resolveAndValidateOptions.ts +40 -0
- package/src/db/adapters/wa-sqlite/ConcurrentConnection.ts +4 -5
- package/src/db/adapters/wa-sqlite/DatabaseClient.ts +20 -56
- package/src/db/adapters/wa-sqlite/DatabaseServer.ts +15 -12
- package/src/db/adapters/wa-sqlite/RawSqliteConnection.ts +35 -24
- package/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.ts +63 -126
- package/src/db/sync/SSRWebStreamingSyncImplementation.ts +4 -22
- package/src/db/sync/SharedWebStreamingSyncImplementation.ts +38 -77
- package/src/db/sync/WebRemote.ts +23 -26
- package/src/db/sync/WebStreamingSyncImplementation.ts +4 -5
- package/src/index.ts +1 -3
- package/src/worker/SharedWorkerConnectionRequest.ts +6 -0
- package/src/worker/client.ts +100 -0
- package/src/worker/db/MultiDatabaseServer.ts +40 -22
- package/src/worker/sync/AbstractSharedSyncClientProvider.ts +4 -10
- package/src/worker/sync/BroadcastLogger.ts +35 -103
- package/src/worker/sync/SharedSyncImplementation.ts +62 -63
- package/src/worker/sync/WorkerClient.ts +4 -4
- package/src/worker/worker.ts +38 -0
- package/dist/index.umd.js +0 -7613
- package/dist/index.umd.js.map +0 -1
- package/dist/worker/SharedSyncImplementation.umd.js +0 -15885
- package/dist/worker/SharedSyncImplementation.umd.js.map +0 -1
- package/dist/worker/WASQLiteDB.umd.js +0 -17164
- package/dist/worker/WASQLiteDB.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-9af0a7.umd.js +0 -31
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-9af0a7.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-bbf5a9.umd.js +0 -31
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-bbf5a9.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-c26e0f.umd.js +0 -31
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-c26e0f.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js +0 -31
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422.umd.js +0 -3562
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23.umd.js +0 -2478
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911.umd.js +0 -1681
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js +0 -1820
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js.map +0 -1
- package/lib/package.json +0 -91
- package/lib/src/db/PowerSyncDatabase.d.ts +0 -78
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.d.ts +0 -23
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js +0 -26
- package/lib/src/db/adapters/AsyncWebAdapter.d.ts +0 -50
- package/lib/src/db/adapters/SSRDBAdapter.d.ts +0 -30
- package/lib/src/db/adapters/SSRDBAdapter.js +0 -68
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +0 -45
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +0 -145
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.d.ts +0 -15
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js +0 -21
- package/lib/src/db/adapters/web-sql-flags.d.ts +0 -92
- package/lib/src/db/adapters/web-sql-flags.js +0 -36
- package/lib/src/db/sync/WebRemote.d.ts +0 -7
- package/lib/src/db/sync/WebRemote.js +0 -32
- package/lib/src/worker/db/MultiDatabaseServer.d.ts +0 -17
- package/lib/src/worker/db/WASQLiteDB.worker.d.ts +0 -4
- package/lib/src/worker/db/WASQLiteDB.worker.js +0 -30
- package/lib/src/worker/db/open-worker-database.d.ts +0 -14
- package/lib/src/worker/db/open-worker-database.js +0 -52
- package/lib/src/worker/sync/AbstractSharedSyncClientProvider.d.ts +0 -19
- package/lib/src/worker/sync/BroadcastLogger.d.ts +0 -47
- package/lib/src/worker/sync/BroadcastLogger.js +0 -128
- package/lib/src/worker/sync/SharedSyncImplementation.worker.d.ts +0 -1
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js +0 -11
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.ts +0 -47
- package/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.ts +0 -24
- package/src/db/adapters/web-sql-flags.ts +0 -141
- package/src/worker/db/WASQLiteDB.worker.ts +0 -35
- package/src/worker/db/open-worker-database.ts +0 -62
- package/src/worker/sync/SharedSyncImplementation.worker.ts +0 -14
- /package/dist/{8e97452e297be23b5e50.wasm → worker/assets/mc-wa-sqlite-CnHbhWvs.wasm} +0 -0
- /package/dist/{2075a31bb151adbb9767.wasm → worker/assets/mc-wa-sqlite-async-D6idQS2r.wasm} +0 -0
- /package/dist/{3322bc84de986b63c2cd.wasm → worker/assets/wa-sqlite-XZW__iJk.wasm} +0 -0
- /package/dist/{fbc178b70d530e8ce02b.wasm → worker/assets/wa-sqlite-async-rHzzC98y.wasm} +0 -0
- /package/lib/{src/attachments → attachments}/IndexDBFileSystemAdapter.d.ts +0 -0
- /package/lib/{src/db → db}/adapters/wa-sqlite/vfs.d.ts +0 -0
- /package/lib/{src/db → db}/sync/userAgent.d.ts +0 -0
- /package/lib/{src/shared → shared}/navigator.d.ts +0 -0
- /package/lib/{src/shared → shared}/tab_close_signal.d.ts +0 -0
- /package/lib/{src/db/adapters/WebDBAdapter.js → worker/worker.d.ts} +0 -0
|
@@ -1,70 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DBAdapter, LogLevels, PowerSyncLogger, SQLOpenFactory } from '@powersync/common';
|
|
2
2
|
import * as Comlink from 'comlink';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
DEFAULT_CACHE_SIZE_KB,
|
|
6
|
-
isServerSide,
|
|
7
|
-
ResolvedWebSQLFlags,
|
|
8
|
-
ResolvedWebSQLOpenOptions,
|
|
9
|
-
resolveWebSQLFlags,
|
|
10
|
-
TemporaryStorageOption,
|
|
11
|
-
WebSQLOpenFactoryOptions
|
|
12
|
-
} from '../web-sql-flags.js';
|
|
3
|
+
import { ResolvedWebSQLOpenOptions, WebSQLOpenOptions } from '../options.js';
|
|
13
4
|
import { SSRDBAdapter } from '../SSRDBAdapter.js';
|
|
14
5
|
import { vfsRequiresDedicatedWorkers, WASQLiteVFS } from './vfs.js';
|
|
15
6
|
import { MultiDatabaseServer } from '../../../worker/db/MultiDatabaseServer.js';
|
|
16
7
|
import { DatabaseClient, OpenWorkerConnection } from './DatabaseClient.js';
|
|
17
8
|
import { generateTabCloseSignal } from '../../../shared/tab_close_signal.js';
|
|
18
9
|
import { AsyncDbAdapter, PoolConnection } from '../AsyncWebAdapter.js';
|
|
10
|
+
import { RawWaSqliteDatabaseOptions } from './RawSqliteConnection.js';
|
|
11
|
+
import { resolveAndValidateOptions } from '../resolveAndValidateOptions.js';
|
|
12
|
+
import { connectToExistingWorker, connectToWorker, WorkerConnection } from '../../../worker/client.js';
|
|
19
13
|
|
|
20
|
-
export interface WASQLiteOpenFactoryOptions
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* If the {@link vfs} supports it, an additional amount of read-only connections to open. Using additional read
|
|
24
|
-
* connections can speed up queries by dispatching them to multiple workers running them concurrently.
|
|
25
|
-
*
|
|
26
|
-
* {@link WASQLiteVFS.OPFSWriteAheadVFS} is the only VFS with support for multiple connections, so this option is
|
|
27
|
-
* ignored for other VFS implementations.
|
|
28
|
-
*
|
|
29
|
-
* Defaults to 1.
|
|
30
|
-
*/
|
|
31
|
-
additionalReaders?: number;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface ResolvedWASQLiteOpenFactoryOptions extends ResolvedWebSQLOpenOptions {
|
|
35
|
-
vfs: WASQLiteVFS;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Whether this is a read-only connection opened for the `OPFSWriteAheadVFS` file system.
|
|
39
|
-
*/
|
|
40
|
-
isReadOnly: boolean;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface WorkerDBOpenerOptions extends ResolvedWASQLiteOpenFactoryOptions {
|
|
44
|
-
logLevel: ILogLevel;
|
|
45
|
-
/**
|
|
46
|
-
* A lock that is currently held by the client. When the lock is returned, we know the client is gone and that we need
|
|
47
|
-
* to clean up resources.
|
|
48
|
-
*/
|
|
49
|
-
lockName: string;
|
|
14
|
+
export interface WASQLiteOpenFactoryOptions {
|
|
15
|
+
open: WebSQLOpenOptions;
|
|
16
|
+
logger: PowerSyncLogger;
|
|
50
17
|
}
|
|
51
18
|
|
|
52
19
|
/**
|
|
53
20
|
* Opens a SQLite connection using WA-SQLite.
|
|
54
21
|
*/
|
|
55
22
|
export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
56
|
-
private
|
|
57
|
-
private logger:
|
|
58
|
-
|
|
59
|
-
constructor(private options: WASQLiteOpenFactoryOptions) {
|
|
60
|
-
assertValidWASQLiteOpenFactoryOptions(options);
|
|
61
|
-
this.resolvedFlags = resolveWebSQLFlags(options.flags);
|
|
62
|
-
this.logger = options.logger ?? createLogger(`WASQLiteOpenFactory - ${this.options.dbFilename}`);
|
|
63
|
-
}
|
|
23
|
+
private options: ResolvedWebSQLOpenOptions;
|
|
24
|
+
private logger: PowerSyncLogger;
|
|
64
25
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
26
|
+
constructor(options: WASQLiteOpenFactoryOptions) {
|
|
27
|
+
this.options = resolveAndValidateOptions(options.open);
|
|
28
|
+
this.logger = options.logger;
|
|
68
29
|
}
|
|
69
30
|
|
|
70
31
|
protected openAdapter(): DBAdapter {
|
|
@@ -72,84 +33,80 @@ export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
|
72
33
|
}
|
|
73
34
|
|
|
74
35
|
openDB(): DBAdapter {
|
|
75
|
-
const {
|
|
76
|
-
|
|
77
|
-
} = this;
|
|
36
|
+
const { disableSSRWarning, enableMultiTabs, ssrMode } = this.options;
|
|
37
|
+
|
|
78
38
|
if (ssrMode) {
|
|
79
39
|
if (!disableSSRWarning) {
|
|
80
|
-
this.logger.
|
|
81
|
-
|
|
40
|
+
this.logger.log({
|
|
41
|
+
level: LogLevels.warn,
|
|
42
|
+
message: `
|
|
82
43
|
Running PowerSync in SSR mode.
|
|
83
44
|
Only empty query results will be returned.
|
|
84
45
|
Disable this warning by setting 'disableSSRWarning: true' in options.`
|
|
85
|
-
);
|
|
46
|
+
});
|
|
86
47
|
}
|
|
87
48
|
|
|
88
49
|
return new SSRDBAdapter();
|
|
89
50
|
}
|
|
90
51
|
|
|
91
52
|
if (!enableMultiTabs) {
|
|
92
|
-
this.logger.
|
|
93
|
-
|
|
94
|
-
|
|
53
|
+
this.logger.log({
|
|
54
|
+
level: LogLevels.warn,
|
|
55
|
+
message: 'Multiple tab support is not enabled. Using this site across multiple tabs may not function correctly.'
|
|
56
|
+
});
|
|
95
57
|
}
|
|
96
58
|
|
|
97
59
|
return this.openAdapter();
|
|
98
60
|
}
|
|
99
61
|
|
|
100
62
|
async openConnection(): Promise<PoolConnection> {
|
|
101
|
-
const { enableMultiTabs, useWebWorker } =
|
|
102
|
-
|
|
103
|
-
vfs = WASQLiteVFS.IDBBatchAtomicVFS,
|
|
104
|
-
temporaryStorage = TemporaryStorageOption.MEMORY,
|
|
105
|
-
cacheSizeKb = DEFAULT_CACHE_SIZE_KB,
|
|
106
|
-
encryptionKey
|
|
107
|
-
} = this.waOptions;
|
|
63
|
+
const { enableMultiTabs, useWebWorker, vfs, dbFilename, encryptionKey, temporaryStorage, cacheSizeKb } =
|
|
64
|
+
this.options;
|
|
108
65
|
|
|
109
66
|
if (!enableMultiTabs) {
|
|
110
|
-
this.logger.warn
|
|
67
|
+
this.logger.log({ level: LogLevels.warn, message: 'Multiple tabs are not enabled in this browser' });
|
|
111
68
|
}
|
|
112
69
|
|
|
113
|
-
const resolveOptions = (isReadOnly: boolean): ResolvedWASQLiteOpenFactoryOptions => ({
|
|
114
|
-
dbFilename: this.options.dbFilename,
|
|
115
|
-
dbLocation: this.options.dbLocation,
|
|
116
|
-
debugMode: this.options.debugMode,
|
|
117
|
-
vfs,
|
|
118
|
-
temporaryStorage,
|
|
119
|
-
cacheSizeKb,
|
|
120
|
-
flags: this.resolvedFlags,
|
|
121
|
-
encryptionKey: encryptionKey,
|
|
122
|
-
isReadOnly
|
|
123
|
-
});
|
|
124
|
-
|
|
125
70
|
let client: DatabaseClient;
|
|
126
71
|
let additionalReaders: DatabaseClient[] = [];
|
|
127
72
|
let requiresPersistentTriggers = vfsRequiresDedicatedWorkers(vfs);
|
|
128
73
|
|
|
74
|
+
function resolveRawWaSqliteDatabaseOptions(readonly: boolean): RawWaSqliteDatabaseOptions {
|
|
75
|
+
return {
|
|
76
|
+
filename: dbFilename,
|
|
77
|
+
readonly,
|
|
78
|
+
vfs,
|
|
79
|
+
encryptionKey,
|
|
80
|
+
temporaryStorage,
|
|
81
|
+
cacheSizeKb
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
129
85
|
if (useWebWorker) {
|
|
130
86
|
const optionsDbWorker = this.options.worker;
|
|
131
87
|
|
|
132
|
-
const openDatabaseWorker = async (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
88
|
+
const openDatabaseWorker = async (readonly: boolean): Promise<DatabaseClient> => {
|
|
89
|
+
let workerConnection: WorkerConnection;
|
|
90
|
+
if (typeof optionsDbWorker == 'function') {
|
|
91
|
+
const worker = optionsDbWorker(this.options);
|
|
92
|
+
workerConnection = connectToExistingWorker(worker, 'database');
|
|
93
|
+
} else {
|
|
94
|
+
const needsDedicated = vfsRequiresDedicatedWorkers(vfs);
|
|
95
|
+
const useShared = !needsDedicated && enableMultiTabs;
|
|
96
|
+
|
|
97
|
+
workerConnection = connectToWorker({
|
|
98
|
+
service: 'database',
|
|
99
|
+
databaseIdentifier: this.options.dbFilename,
|
|
100
|
+
shared: useShared,
|
|
101
|
+
customWorker: optionsDbWorker
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const source = Comlink.wrap<OpenWorkerConnection>(workerConnection.endpoint);
|
|
149
106
|
const closeSignal = new AbortController();
|
|
150
107
|
const connection = await source.connect({
|
|
151
|
-
|
|
152
|
-
logLevel: this.
|
|
108
|
+
database: resolveRawWaSqliteDatabaseOptions(readonly),
|
|
109
|
+
logLevel: this.options.databaseWorkerLogLevel,
|
|
153
110
|
lockName: await generateTabCloseSignal(closeSignal.signal)
|
|
154
111
|
});
|
|
155
112
|
const clientOptions = {
|
|
@@ -159,28 +116,24 @@ export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
|
159
116
|
remoteCanCloseUnexpectedly: false,
|
|
160
117
|
onClose: () => {
|
|
161
118
|
closeSignal.abort();
|
|
162
|
-
|
|
163
|
-
workerPort.terminate();
|
|
164
|
-
} else {
|
|
165
|
-
workerPort.close();
|
|
166
|
-
}
|
|
119
|
+
workerConnection.close();
|
|
167
120
|
}
|
|
168
121
|
};
|
|
169
122
|
|
|
170
123
|
return new DatabaseClient(clientOptions, {
|
|
171
|
-
...
|
|
124
|
+
...this.options,
|
|
172
125
|
requiresPersistentTriggers
|
|
173
126
|
});
|
|
174
127
|
};
|
|
175
128
|
|
|
176
|
-
client = await openDatabaseWorker(
|
|
129
|
+
client = await openDatabaseWorker(false);
|
|
177
130
|
|
|
178
131
|
if (vfs == WASQLiteVFS.OPFSWriteAheadVFS) {
|
|
179
132
|
// This VFS supports concurrent reads, so we can open additional workers to host read-only connections for
|
|
180
133
|
// concurrent reads / writes.
|
|
181
134
|
const additionalReadersCount = this.options.additionalReaders ?? 1;
|
|
182
135
|
for (let i = 0; i < additionalReadersCount; i++) {
|
|
183
|
-
const reader = await openDatabaseWorker(
|
|
136
|
+
const reader = await openDatabaseWorker(true);
|
|
184
137
|
additionalReaders.push(reader);
|
|
185
138
|
}
|
|
186
139
|
}
|
|
@@ -189,12 +142,11 @@ export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
|
189
142
|
const localServer = new MultiDatabaseServer(this.logger);
|
|
190
143
|
requiresPersistentTriggers = true;
|
|
191
144
|
|
|
192
|
-
const
|
|
193
|
-
const connection = await localServer.openConnectionLocally(resolvedOptions);
|
|
145
|
+
const connection = await localServer.openConnectionLocally(this.logger, resolveRawWaSqliteDatabaseOptions(false));
|
|
194
146
|
client = new DatabaseClient(
|
|
195
147
|
{ connection, source: null, remoteCanCloseUnexpectedly: false },
|
|
196
148
|
{
|
|
197
|
-
...
|
|
149
|
+
...this.options,
|
|
198
150
|
requiresPersistentTriggers
|
|
199
151
|
}
|
|
200
152
|
);
|
|
@@ -206,18 +158,3 @@ export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
|
206
158
|
};
|
|
207
159
|
}
|
|
208
160
|
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Asserts that the factory options are valid.
|
|
212
|
-
*/
|
|
213
|
-
function assertValidWASQLiteOpenFactoryOptions(options: WASQLiteOpenFactoryOptions): void {
|
|
214
|
-
// The OPFS VFS only works in dedicated web workers.
|
|
215
|
-
if ('vfs' in options && 'flags' in options) {
|
|
216
|
-
const { vfs, flags = {} } = options;
|
|
217
|
-
if (vfs && vfsRequiresDedicatedWorkers(vfs) && 'useWebWorker' in flags && !flags.useWebWorker) {
|
|
218
|
-
throw new Error(
|
|
219
|
-
`Invalid configuration: The 'useWebWorker' flag must be true when using an OPFS-based VFS (${vfs}).`
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
BaseObserver,
|
|
4
|
-
LockOptions,
|
|
5
|
-
LockType,
|
|
6
|
-
Mutex,
|
|
7
|
-
PowerSyncConnectionOptions,
|
|
8
|
-
StreamingSyncImplementation,
|
|
9
|
-
SyncStatus,
|
|
10
|
-
SyncStatusOptions
|
|
11
|
-
} from '@powersync/common';
|
|
1
|
+
import { BaseObserver, SyncStatus } from '@powersync/common';
|
|
2
|
+
import { Mutex, StreamingSyncImplementation, LockOptions, LockType } from '@powersync/shared-internals';
|
|
12
3
|
|
|
13
4
|
export class SSRStreamingSyncImplementation extends BaseObserver implements StreamingSyncImplementation {
|
|
14
5
|
syncMutex: Mutex;
|
|
@@ -16,13 +7,11 @@ export class SSRStreamingSyncImplementation extends BaseObserver implements Stre
|
|
|
16
7
|
|
|
17
8
|
isConnected: boolean;
|
|
18
9
|
lastSyncedAt?: Date | undefined;
|
|
19
|
-
syncStatus: SyncStatus;
|
|
20
10
|
|
|
21
|
-
constructor(
|
|
11
|
+
constructor() {
|
|
22
12
|
super();
|
|
23
13
|
this.syncMutex = new Mutex();
|
|
24
14
|
this.crudMutex = new Mutex();
|
|
25
|
-
this.syncStatus = new SyncStatus({});
|
|
26
15
|
this.isConnected = false;
|
|
27
16
|
}
|
|
28
17
|
|
|
@@ -34,7 +23,7 @@ export class SSRStreamingSyncImplementation extends BaseObserver implements Stre
|
|
|
34
23
|
/**
|
|
35
24
|
* This is a no-op in SSR mode
|
|
36
25
|
*/
|
|
37
|
-
async connect(
|
|
26
|
+
async connect(): Promise<void> {}
|
|
38
27
|
|
|
39
28
|
async dispose() {}
|
|
40
29
|
|
|
@@ -48,13 +37,6 @@ export class SSRStreamingSyncImplementation extends BaseObserver implements Stre
|
|
|
48
37
|
*/
|
|
49
38
|
async waitForReady() {}
|
|
50
39
|
|
|
51
|
-
/**
|
|
52
|
-
* This will never resolve in SSR Mode.
|
|
53
|
-
*/
|
|
54
|
-
async waitForStatus(status: SyncStatusOptions) {
|
|
55
|
-
return this.waitUntilStatusMatches(() => false);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
40
|
/**
|
|
59
41
|
* This will never resolve in SSR Mode.
|
|
60
42
|
*/
|
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PowerSyncConnectionOptions,
|
|
3
|
-
PowerSyncCredentials,
|
|
4
|
-
SubscribedStream,
|
|
5
|
-
SyncStatusOptions
|
|
6
|
-
} from '@powersync/common';
|
|
1
|
+
import { LogRecord, PowerSyncCredentials } from '@powersync/common';
|
|
7
2
|
import * as Comlink from 'comlink';
|
|
8
|
-
import { getNavigatorLocks } from '../../shared/navigator.js';
|
|
9
3
|
import { AbstractSharedSyncClientProvider } from '../../worker/sync/AbstractSharedSyncClientProvider.js';
|
|
10
4
|
import { ManualSharedSyncPayload, SharedSyncClientEvent } from '../../worker/sync/SharedSyncImplementation.js';
|
|
11
5
|
import { WorkerClient } from '../../worker/sync/WorkerClient.js';
|
|
12
6
|
import { WebDBAdapter } from '../adapters/WebDBAdapter.js';
|
|
13
|
-
import { DEFAULT_CACHE_SIZE_KB, TemporaryStorageOption, resolveWebSQLFlags } from '../adapters/web-sql-flags.js';
|
|
14
7
|
import {
|
|
15
8
|
WebStreamingSyncImplementation,
|
|
16
9
|
WebStreamingSyncImplementationOptions
|
|
17
10
|
} from './WebStreamingSyncImplementation.js';
|
|
18
11
|
import { generateTabCloseSignal } from '../../shared/tab_close_signal.js';
|
|
12
|
+
import { SubscribedStream, SyncStatusJson, ResolvedSyncOptions } from '@powersync/shared-internals';
|
|
13
|
+
import { connectToExistingWorker, connectToWorker, WorkerConnection } from '../../worker/client.js';
|
|
19
14
|
|
|
20
15
|
/**
|
|
21
16
|
* The shared worker will trigger methods on this side of the message port
|
|
@@ -24,7 +19,7 @@ import { generateTabCloseSignal } from '../../shared/tab_close_signal.js';
|
|
|
24
19
|
class SharedSyncClientProvider extends AbstractSharedSyncClientProvider {
|
|
25
20
|
constructor(
|
|
26
21
|
protected options: WebStreamingSyncImplementationOptions,
|
|
27
|
-
public statusChanged: (status:
|
|
22
|
+
public statusChanged: (status: SyncStatusJson) => void,
|
|
28
23
|
protected webDB: WebDBAdapter
|
|
29
24
|
) {
|
|
30
25
|
super();
|
|
@@ -68,34 +63,15 @@ class SharedSyncClientProvider extends AbstractSharedSyncClientProvider {
|
|
|
68
63
|
return this.options.logger;
|
|
69
64
|
}
|
|
70
65
|
|
|
71
|
-
|
|
72
|
-
this.logger
|
|
73
|
-
}
|
|
74
|
-
debug(...x: any[]): void {
|
|
75
|
-
this.logger?.debug(...x);
|
|
76
|
-
}
|
|
77
|
-
info(...x: any[]): void {
|
|
78
|
-
this.logger?.info(...x);
|
|
79
|
-
}
|
|
80
|
-
log(...x: any[]): void {
|
|
81
|
-
this.logger?.log(...x);
|
|
82
|
-
}
|
|
83
|
-
warn(...x: any[]): void {
|
|
84
|
-
this.logger?.warn(...x);
|
|
85
|
-
}
|
|
86
|
-
error(...x: any[]): void {
|
|
87
|
-
this.logger?.error(...x);
|
|
88
|
-
}
|
|
89
|
-
time(label: string): void {
|
|
90
|
-
this.logger?.time(label);
|
|
91
|
-
}
|
|
92
|
-
timeEnd(label: string): void {
|
|
93
|
-
this.logger?.timeEnd(label);
|
|
66
|
+
log(record: LogRecord): void {
|
|
67
|
+
this.logger.log(record);
|
|
94
68
|
}
|
|
95
69
|
}
|
|
96
70
|
|
|
97
71
|
export interface SharedWebStreamingSyncImplementationOptions extends WebStreamingSyncImplementationOptions {
|
|
72
|
+
logLevel: number;
|
|
98
73
|
db: WebDBAdapter;
|
|
74
|
+
enableBroadcastLogs: boolean;
|
|
99
75
|
}
|
|
100
76
|
|
|
101
77
|
/**
|
|
@@ -104,46 +80,30 @@ export interface SharedWebStreamingSyncImplementationOptions extends WebStreamin
|
|
|
104
80
|
export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplementation {
|
|
105
81
|
protected syncManager: Comlink.Remote<WorkerClient>;
|
|
106
82
|
protected clientProvider: SharedSyncClientProvider;
|
|
107
|
-
protected
|
|
83
|
+
protected worker: WorkerConnection;
|
|
108
84
|
|
|
109
85
|
protected isInitialized: Promise<void>;
|
|
110
86
|
protected dbAdapter: WebDBAdapter;
|
|
111
87
|
private abortOnClose = new AbortController();
|
|
88
|
+
private logLevel: number;
|
|
89
|
+
private enableBroadcastLogs: boolean;
|
|
112
90
|
|
|
113
91
|
constructor(options: SharedWebStreamingSyncImplementationOptions) {
|
|
114
92
|
super(options);
|
|
115
93
|
this.dbAdapter = options.db;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
* This worker will manage all syncing operations remotely.
|
|
119
|
-
*/
|
|
120
|
-
const resolvedWorkerOptions = {
|
|
121
|
-
dbFilename: this.options.identifier!,
|
|
122
|
-
temporaryStorage: TemporaryStorageOption.MEMORY,
|
|
123
|
-
cacheSizeKb: DEFAULT_CACHE_SIZE_KB,
|
|
124
|
-
...options,
|
|
125
|
-
flags: resolveWebSQLFlags(options.flags)
|
|
126
|
-
};
|
|
94
|
+
this.logLevel = options.logLevel;
|
|
95
|
+
this.enableBroadcastLogs = options.enableBroadcastLogs;
|
|
127
96
|
|
|
128
97
|
const syncWorker = options.sync?.worker;
|
|
129
|
-
if (syncWorker) {
|
|
130
|
-
|
|
131
|
-
this.messagePort = syncWorker(resolvedWorkerOptions).port;
|
|
132
|
-
} else {
|
|
133
|
-
this.messagePort = new SharedWorker(`${syncWorker}`, {
|
|
134
|
-
/* @vite-ignore */
|
|
135
|
-
name: `shared-sync-${this.webOptions.identifier}`
|
|
136
|
-
}).port;
|
|
137
|
-
}
|
|
98
|
+
if (typeof syncWorker === 'function') {
|
|
99
|
+
this.worker = connectToExistingWorker(syncWorker(), 'sync');
|
|
138
100
|
} else {
|
|
139
|
-
this.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
).port;
|
|
101
|
+
this.worker = connectToWorker({
|
|
102
|
+
service: 'sync',
|
|
103
|
+
databaseIdentifier: this.webOptions.identifier!,
|
|
104
|
+
shared: true,
|
|
105
|
+
customWorker: syncWorker
|
|
106
|
+
});
|
|
147
107
|
}
|
|
148
108
|
|
|
149
109
|
/**
|
|
@@ -151,21 +111,21 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
151
111
|
*/
|
|
152
112
|
this.clientProvider = new SharedSyncClientProvider(
|
|
153
113
|
this.webOptions,
|
|
154
|
-
(
|
|
155
|
-
this.updateSyncStatus(
|
|
114
|
+
({ core, dataFlow }) => {
|
|
115
|
+
this.updateSyncStatus(core, dataFlow);
|
|
156
116
|
},
|
|
157
117
|
options.db
|
|
158
118
|
);
|
|
159
119
|
|
|
160
|
-
this.syncManager = Comlink.wrap<WorkerClient>(this.
|
|
120
|
+
this.syncManager = Comlink.wrap<WorkerClient>(this.worker.endpoint);
|
|
161
121
|
/**
|
|
162
122
|
* The sync worker will call this client provider when it needs
|
|
163
123
|
* to fetch credentials or upload data.
|
|
164
124
|
* This performs bi-directional method calling.
|
|
165
125
|
*/
|
|
166
|
-
Comlink.expose(this.clientProvider, this.
|
|
126
|
+
Comlink.expose(this.clientProvider, this.worker.endpoint);
|
|
167
127
|
|
|
168
|
-
this.syncManager.setLogLevel(this.
|
|
128
|
+
this.syncManager.setLogLevel(this.logLevel);
|
|
169
129
|
|
|
170
130
|
this.triggerCrudUpload = this.syncManager.triggerCrudUpload;
|
|
171
131
|
|
|
@@ -197,18 +157,16 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
197
157
|
// Awaiting here ensures the worker is waiting for the lock
|
|
198
158
|
await this.syncManager.addLockBasedCloseSignal(closeSignal);
|
|
199
159
|
|
|
200
|
-
const {
|
|
201
|
-
const flags = { ...this.webOptions.flags, workers: undefined };
|
|
160
|
+
const { identifier } = this.options;
|
|
202
161
|
|
|
203
162
|
await this.syncManager.setParams(
|
|
204
163
|
{
|
|
205
164
|
dbParams: this.dbAdapter.getConfiguration(),
|
|
206
165
|
streamOptions: {
|
|
207
|
-
crudUploadThrottleMs,
|
|
208
166
|
identifier,
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
167
|
+
serializedSchema: this.options.serializedSchema
|
|
168
|
+
},
|
|
169
|
+
enableBroadcastLogs: this.enableBroadcastLogs
|
|
212
170
|
},
|
|
213
171
|
this.options.subscriptions
|
|
214
172
|
);
|
|
@@ -218,9 +176,9 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
218
176
|
* Starts the sync process, this effectively acts as a call to
|
|
219
177
|
* `connect` if not yet connected.
|
|
220
178
|
*/
|
|
221
|
-
async connect(options
|
|
179
|
+
async connect(options: ResolvedSyncOptions): Promise<void> {
|
|
222
180
|
await this.waitForReady();
|
|
223
|
-
return this.syncManager.connect(options);
|
|
181
|
+
return this.syncManager.connect(options, this.options.serializedSchema);
|
|
224
182
|
}
|
|
225
183
|
|
|
226
184
|
async disconnect(): Promise<void> {
|
|
@@ -237,8 +195,11 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
237
195
|
await this.waitForReady();
|
|
238
196
|
|
|
239
197
|
await new Promise<void>((resolve) => {
|
|
198
|
+
// This will always be a message port since we use shared workers.
|
|
199
|
+
const messagePort = this.worker.endpoint as MessagePort;
|
|
200
|
+
|
|
240
201
|
// Listen for the close acknowledgment from the worker
|
|
241
|
-
|
|
202
|
+
messagePort.addEventListener('message', (event) => {
|
|
242
203
|
const payload = event.data as ManualSharedSyncPayload;
|
|
243
204
|
if (payload?.event === SharedSyncClientEvent.CLOSE_ACK) {
|
|
244
205
|
resolve();
|
|
@@ -250,7 +211,7 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
250
211
|
event: SharedSyncClientEvent.CLOSE_CLIENT,
|
|
251
212
|
data: {}
|
|
252
213
|
};
|
|
253
|
-
|
|
214
|
+
messagePort.postMessage(closeMessagePayload);
|
|
254
215
|
});
|
|
255
216
|
|
|
256
217
|
await super.dispose();
|
|
@@ -259,7 +220,7 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
259
220
|
|
|
260
221
|
// Release the proxy
|
|
261
222
|
this.syncManager[Comlink.releaseProxy]();
|
|
262
|
-
this.
|
|
223
|
+
this.worker.close();
|
|
263
224
|
}
|
|
264
225
|
|
|
265
226
|
async waitForReady() {
|
package/src/db/sync/WebRemote.ts
CHANGED
|
@@ -1,43 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
AbstractRemoteOptions,
|
|
4
|
-
DEFAULT_REMOTE_LOGGER,
|
|
5
|
-
FetchImplementation,
|
|
6
|
-
FetchImplementationProvider,
|
|
7
|
-
ILogger,
|
|
8
|
-
RemoteConnector
|
|
9
|
-
} from '@powersync/common';
|
|
1
|
+
import { LogLevels, PowerSyncLogger } from '@powersync/common';
|
|
2
|
+
import { AbstractRemote, FetchOptions, RemoteConnector } from '@powersync/shared-internals';
|
|
10
3
|
|
|
11
4
|
import { getUserAgentInfo } from './userAgent.js';
|
|
12
|
-
|
|
13
|
-
/*
|
|
14
|
-
* Depends on browser's implementation of global fetch.
|
|
15
|
-
*/
|
|
16
|
-
class WebFetchProvider extends FetchImplementationProvider {
|
|
17
|
-
getFetch(): FetchImplementation {
|
|
18
|
-
return fetch.bind(globalThis);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
5
|
+
import type { WebSocketSyncStreamPlatform, WebSocketSupport } from '@powersync/shared-internals/websockets';
|
|
21
6
|
|
|
22
7
|
export class WebRemote extends AbstractRemote {
|
|
23
8
|
constructor(
|
|
24
9
|
protected connector: RemoteConnector,
|
|
25
|
-
|
|
26
|
-
options?: Partial<AbstractRemoteOptions>
|
|
10
|
+
logger: PowerSyncLogger
|
|
27
11
|
) {
|
|
28
|
-
super(connector, logger
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
12
|
+
super(connector, logger);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
protected fetch({ resource, request }: FetchOptions): Promise<Response> {
|
|
16
|
+
return fetch(resource, request);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
protected async loadWebSocketSupport(platform: WebSocketSyncStreamPlatform): Promise<WebSocketSupport> {
|
|
20
|
+
if (!websockets) {
|
|
21
|
+
// loadWebSocketSupport being called concurrently is safe, the import resolves to the same module in that case.
|
|
22
|
+
const module = await import('@powersync/shared-internals/websockets');
|
|
23
|
+
websockets = new module.WebSocketSupport(platform);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return websockets;
|
|
32
27
|
}
|
|
33
28
|
|
|
34
29
|
getUserAgent(): string {
|
|
35
30
|
let ua = [super.getUserAgent(), `powersync-web`];
|
|
36
31
|
try {
|
|
37
32
|
ua.push(...getUserAgentInfo());
|
|
38
|
-
} catch (
|
|
39
|
-
this.logger.warn
|
|
33
|
+
} catch (error) {
|
|
34
|
+
this.logger.log({ level: LogLevels.warn, message: 'Failed to get user agent info', error });
|
|
40
35
|
}
|
|
41
36
|
return ua.join(' ');
|
|
42
37
|
}
|
|
43
38
|
}
|
|
39
|
+
|
|
40
|
+
let websockets: WebSocketSupport | undefined;
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
+
import { LogLevels } from '@powersync/common';
|
|
1
2
|
import {
|
|
2
3
|
AbstractStreamingSyncImplementation,
|
|
3
4
|
AbstractStreamingSyncImplementationOptions,
|
|
4
5
|
LockOptions,
|
|
5
6
|
LockType
|
|
6
|
-
} from '@powersync/
|
|
7
|
+
} from '@powersync/shared-internals';
|
|
7
8
|
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
|
-
flags?: WebSQLFlags;
|
|
12
11
|
sync?: {
|
|
13
|
-
worker?: string | URL | ((
|
|
12
|
+
worker?: string | URL | (() => SharedWorker);
|
|
14
13
|
};
|
|
15
14
|
}
|
|
16
15
|
|
|
@@ -27,7 +26,7 @@ export class WebStreamingSyncImplementation extends AbstractStreamingSyncImpleme
|
|
|
27
26
|
async obtainLock<T>(lockOptions: LockOptions<T>): Promise<T> {
|
|
28
27
|
const identifier = `streaming-sync-${lockOptions.type}-${this.webOptions.identifier}`;
|
|
29
28
|
if (lockOptions.type == LockType.SYNC) {
|
|
30
|
-
this.logger.debug
|
|
29
|
+
this.logger.log({ level: LogLevels.debug, message: `requesting lock for ${identifier}` });
|
|
31
30
|
}
|
|
32
31
|
return getNavigatorLocks().request(identifier, { signal: lockOptions.signal }, lockOptions.callback);
|
|
33
32
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export * from '@powersync/common';
|
|
2
2
|
export * from './attachments/IndexDBFileSystemAdapter.js';
|
|
3
|
-
export * from './db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js';
|
|
4
3
|
export { WASQLiteVFS } from './db/adapters/wa-sqlite/vfs.js';
|
|
5
4
|
export * from './db/adapters/wa-sqlite/WASQLiteOpenFactory.js';
|
|
6
|
-
export * from './db/adapters/
|
|
7
|
-
export * from './db/adapters/web-sql-flags.js';
|
|
5
|
+
export * from './db/adapters/options.js';
|
|
8
6
|
export * from './db/PowerSyncDatabase.js';
|
|
9
7
|
export * from './db/sync/SharedWebStreamingSyncImplementation.js';
|
|
10
8
|
export * from './db/sync/WebRemote.js';
|