@powersync/web 0.0.0-dev-20260630141119 → 0.0.0-dev-20260708103617
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.umd.js +7821 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/worker/SharedSyncImplementation.umd.js +16139 -0
- package/dist/worker/SharedSyncImplementation.umd.js.map +1 -0
- package/dist/worker/WASQLiteDB.umd.js +17434 -0
- package/dist/worker/WASQLiteDB.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-9af0a7.umd.js +31 -0
- 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 +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-bbf5a9.umd.js +31 -0
- 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 +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-c26e0f.umd.js +31 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-c26e0f.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js +31 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422.umd.js +3562 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js +1400 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23.umd.js +2478 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911.umd.js +1681 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js +1820 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js.map +1 -0
- package/lib/package.json +91 -0
- package/lib/src/attachments/IndexDBFileSystemAdapter.js.map +1 -0
- package/lib/{db → src/db}/NavigatorTriggerClaimManager.d.ts +1 -1
- package/lib/src/db/NavigatorTriggerClaimManager.js.map +1 -0
- package/lib/src/db/PowerSyncDatabase.d.ts +78 -0
- package/lib/{db → src/db}/PowerSyncDatabase.js +61 -47
- package/lib/src/db/PowerSyncDatabase.js.map +1 -0
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.d.ts +23 -0
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js +27 -0
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js.map +1 -0
- package/lib/src/db/adapters/AsyncWebAdapter.d.ts +50 -0
- package/lib/{db → src/db}/adapters/AsyncWebAdapter.js +14 -14
- package/lib/src/db/adapters/AsyncWebAdapter.js.map +1 -0
- package/lib/src/db/adapters/SSRDBAdapter.d.ts +30 -0
- package/lib/src/db/adapters/SSRDBAdapter.js +69 -0
- package/lib/src/db/adapters/SSRDBAdapter.js.map +1 -0
- package/lib/{db → src/db}/adapters/WebDBAdapter.d.ts +1 -1
- package/lib/src/db/adapters/WebDBAdapter.js.map +1 -0
- package/lib/{db → src/db}/adapters/wa-sqlite/ConcurrentConnection.d.ts +4 -3
- package/lib/{db → src/db}/adapters/wa-sqlite/ConcurrentConnection.js +2 -2
- package/lib/src/db/adapters/wa-sqlite/ConcurrentConnection.js.map +1 -0
- package/lib/{db → src/db}/adapters/wa-sqlite/DatabaseClient.d.ts +4 -4
- package/lib/{db → src/db}/adapters/wa-sqlite/DatabaseClient.js +37 -11
- package/lib/src/db/adapters/wa-sqlite/DatabaseClient.js.map +1 -0
- package/lib/{db → src/db}/adapters/wa-sqlite/DatabaseServer.d.ts +5 -5
- package/lib/{db → src/db}/adapters/wa-sqlite/DatabaseServer.js +7 -11
- package/lib/src/db/adapters/wa-sqlite/DatabaseServer.js.map +1 -0
- package/lib/{db → src/db}/adapters/wa-sqlite/RawSqliteConnection.d.ts +12 -23
- package/lib/{db → src/db}/adapters/wa-sqlite/RawSqliteConnection.js +11 -17
- package/lib/src/db/adapters/wa-sqlite/RawSqliteConnection.js.map +1 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +45 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +146 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js.map +1 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.d.ts +15 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js +22 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js.map +1 -0
- package/lib/src/db/adapters/wa-sqlite/vfs.d.ts +40 -0
- package/lib/src/db/adapters/wa-sqlite/vfs.js +95 -0
- package/lib/src/db/adapters/wa-sqlite/vfs.js.map +1 -0
- package/lib/src/db/adapters/web-sql-flags.d.ts +92 -0
- package/lib/src/db/adapters/web-sql-flags.js +37 -0
- package/lib/src/db/adapters/web-sql-flags.js.map +1 -0
- package/lib/{db → src/db}/sync/SSRWebStreamingSyncImplementation.d.ts +8 -4
- package/lib/{db → src/db}/sync/SSRWebStreamingSyncImplementation.js +11 -4
- package/lib/src/db/sync/SSRWebStreamingSyncImplementation.js.map +1 -0
- package/lib/{db → src/db}/sync/SharedWebStreamingSyncImplementation.d.ts +14 -13
- package/lib/{db → src/db}/sync/SharedWebStreamingSyncImplementation.js +66 -31
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js.map +1 -0
- package/lib/src/db/sync/WebRemote.d.ts +7 -0
- package/lib/src/db/sync/WebRemote.js +33 -0
- package/lib/src/db/sync/WebRemote.js.map +1 -0
- package/lib/{db → src/db}/sync/WebStreamingSyncImplementation.d.ts +4 -2
- package/lib/{db → src/db}/sync/WebStreamingSyncImplementation.js +2 -3
- package/lib/src/db/sync/WebStreamingSyncImplementation.js.map +1 -0
- package/lib/src/db/sync/userAgent.js.map +1 -0
- package/lib/{index.d.ts → src/index.d.ts} +3 -1
- package/lib/{index.js → src/index.js} +3 -1
- package/lib/src/index.js.map +1 -0
- package/lib/src/shared/navigator.js.map +1 -0
- package/lib/src/shared/tab_close_signal.js.map +1 -0
- package/lib/src/worker/db/MultiDatabaseServer.d.ts +17 -0
- package/lib/{worker → src/worker}/db/MultiDatabaseServer.js +18 -26
- package/lib/src/worker/db/MultiDatabaseServer.js.map +1 -0
- package/lib/src/worker/db/WASQLiteDB.worker.d.ts +4 -0
- package/lib/src/worker/db/WASQLiteDB.worker.js +31 -0
- package/lib/src/worker/db/WASQLiteDB.worker.js.map +1 -0
- package/lib/src/worker/db/open-worker-database.d.ts +14 -0
- package/lib/src/worker/db/open-worker-database.js +53 -0
- package/lib/src/worker/db/open-worker-database.js.map +1 -0
- package/lib/src/worker/sync/AbstractSharedSyncClientProvider.d.ts +19 -0
- package/lib/src/worker/sync/AbstractSharedSyncClientProvider.js.map +1 -0
- package/lib/src/worker/sync/BroadcastLogger.d.ts +47 -0
- package/lib/src/worker/sync/BroadcastLogger.js +129 -0
- package/lib/src/worker/sync/BroadcastLogger.js.map +1 -0
- package/lib/{worker → src/worker}/sync/SharedSyncImplementation.d.ts +15 -11
- package/lib/{worker → src/worker}/sync/SharedSyncImplementation.js +43 -42
- package/lib/src/worker/sync/SharedSyncImplementation.js.map +1 -0
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js +12 -0
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js.map +1 -0
- package/lib/{worker → src/worker}/sync/WorkerClient.d.ts +3 -3
- package/lib/{worker → src/worker}/sync/WorkerClient.js +2 -2
- package/lib/src/worker/sync/WorkerClient.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +29 -22
- package/src/db/NavigatorTriggerClaimManager.ts +1 -1
- package/src/db/PowerSyncDatabase.ts +122 -80
- package/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.ts +47 -0
- package/src/db/adapters/AsyncWebAdapter.ts +26 -17
- package/src/db/adapters/SSRDBAdapter.ts +64 -14
- package/src/db/adapters/WebDBAdapter.ts +1 -1
- package/src/db/adapters/wa-sqlite/ConcurrentConnection.ts +5 -4
- package/src/db/adapters/wa-sqlite/DatabaseClient.ts +56 -20
- package/src/db/adapters/wa-sqlite/DatabaseServer.ts +12 -15
- package/src/db/adapters/wa-sqlite/RawSqliteConnection.ts +24 -41
- package/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.ts +126 -63
- package/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.ts +24 -0
- package/src/db/adapters/wa-sqlite/vfs.ts +67 -54
- package/src/db/adapters/web-sql-flags.ts +141 -0
- package/src/db/sync/SSRWebStreamingSyncImplementation.ts +22 -4
- package/src/db/sync/SharedWebStreamingSyncImplementation.ts +77 -38
- package/src/db/sync/WebRemote.ts +26 -23
- package/src/db/sync/WebStreamingSyncImplementation.ts +5 -4
- package/src/index.ts +3 -1
- package/src/worker/db/MultiDatabaseServer.ts +25 -41
- package/src/worker/db/WASQLiteDB.worker.ts +35 -0
- package/src/worker/db/open-worker-database.ts +62 -0
- package/src/worker/sync/AbstractSharedSyncClientProvider.ts +10 -4
- package/src/worker/sync/BroadcastLogger.ts +103 -35
- package/src/worker/sync/SharedSyncImplementation.ts +63 -62
- package/src/worker/sync/SharedSyncImplementation.worker.ts +14 -0
- package/src/worker/sync/WorkerClient.ts +4 -4
- package/dist/index.react_native_web.js +0 -1879
- package/dist/index.react_native_web.js.map +0 -1
- package/dist/worker/AccessHandlePoolVFS-BPUHfZME.js +0 -2
- package/dist/worker/AccessHandlePoolVFS-BPUHfZME.js.map +0 -1
- package/dist/worker/FacadeVFS-d1ZDvud7.js +0 -2
- package/dist/worker/FacadeVFS-d1ZDvud7.js.map +0 -1
- package/dist/worker/IDBBatchAtomicVFS-DbkDb777.js +0 -2
- package/dist/worker/IDBBatchAtomicVFS-DbkDb777.js.map +0 -1
- package/dist/worker/OPFSCoopSyncVFS-DRKedN0p.js +0 -2
- package/dist/worker/OPFSCoopSyncVFS-DRKedN0p.js.map +0 -1
- package/dist/worker/OPFSWriteAheadVFS-BzodSqNq.js +0 -2
- package/dist/worker/OPFSWriteAheadVFS-BzodSqNq.js.map +0 -1
- package/dist/worker/mc-wa-sqlite-DiBqIVE5.js +0 -2
- package/dist/worker/mc-wa-sqlite-DiBqIVE5.js.map +0 -1
- package/dist/worker/mc-wa-sqlite-async-DUEhO9ef.js +0 -2
- package/dist/worker/mc-wa-sqlite-async-DUEhO9ef.js.map +0 -1
- package/dist/worker/wa-sqlite-BlSx7-_P.js +0 -2
- package/dist/worker/wa-sqlite-BlSx7-_P.js.map +0 -1
- package/dist/worker/wa-sqlite-async-BdR24Ucf.js +0 -2
- package/dist/worker/wa-sqlite-async-BdR24Ucf.js.map +0 -1
- package/dist/worker/websockets-Q8W_lerF.js +0 -9
- package/dist/worker/websockets-Q8W_lerF.js.map +0 -1
- package/dist/worker/worker.js +0 -7
- package/dist/worker/worker.js.map +0 -1
- package/lib/attachments/IndexDBFileSystemAdapter.js.map +0 -1
- package/lib/db/NavigatorTriggerClaimManager.js.map +0 -1
- package/lib/db/PowerSyncDatabase.d.ts +0 -67
- package/lib/db/PowerSyncDatabase.js.map +0 -1
- package/lib/db/adapters/AsyncWebAdapter.d.ts +0 -32
- package/lib/db/adapters/AsyncWebAdapter.js.map +0 -1
- package/lib/db/adapters/SSRDBAdapter.d.ts +0 -17
- package/lib/db/adapters/SSRDBAdapter.js +0 -37
- package/lib/db/adapters/SSRDBAdapter.js.map +0 -1
- package/lib/db/adapters/WebDBAdapter.js.map +0 -1
- package/lib/db/adapters/options.d.ts +0 -87
- package/lib/db/adapters/options.js +0 -6
- package/lib/db/adapters/options.js.map +0 -1
- package/lib/db/adapters/resolveAndValidateOptions.d.ts +0 -5
- package/lib/db/adapters/resolveAndValidateOptions.js +0 -33
- package/lib/db/adapters/resolveAndValidateOptions.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/ConcurrentConnection.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/DatabaseClient.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/DatabaseServer.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/RawSqliteConnection.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +0 -18
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +0 -131
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/vfs.d.ts +0 -50
- package/lib/db/adapters/wa-sqlite/vfs.js +0 -77
- package/lib/db/adapters/wa-sqlite/vfs.js.map +0 -1
- package/lib/db/sync/SSRWebStreamingSyncImplementation.js.map +0 -1
- package/lib/db/sync/SharedWebStreamingSyncImplementation.js.map +0 -1
- package/lib/db/sync/WebRemote.d.ts +0 -10
- package/lib/db/sync/WebRemote.js +0 -33
- package/lib/db/sync/WebRemote.js.map +0 -1
- package/lib/db/sync/WebStreamingSyncImplementation.js.map +0 -1
- package/lib/db/sync/userAgent.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/shared/navigator.js.map +0 -1
- package/lib/shared/tab_close_signal.js.map +0 -1
- package/lib/worker/SharedWorkerConnectionRequest.d.ts +0 -5
- package/lib/worker/SharedWorkerConnectionRequest.js +0 -2
- package/lib/worker/SharedWorkerConnectionRequest.js.map +0 -1
- package/lib/worker/client.d.ts +0 -15
- package/lib/worker/client.js +0 -77
- package/lib/worker/client.js.map +0 -1
- package/lib/worker/db/MultiDatabaseServer.d.ts +0 -22
- package/lib/worker/db/MultiDatabaseServer.js.map +0 -1
- package/lib/worker/sync/AbstractSharedSyncClientProvider.d.ts +0 -13
- package/lib/worker/sync/AbstractSharedSyncClientProvider.js.map +0 -1
- package/lib/worker/sync/BroadcastLogger.d.ts +0 -27
- package/lib/worker/sync/BroadcastLogger.js +0 -65
- package/lib/worker/sync/BroadcastLogger.js.map +0 -1
- package/lib/worker/sync/SharedSyncImplementation.js.map +0 -1
- package/lib/worker/sync/WorkerClient.js.map +0 -1
- package/lib/worker/worker.js +0 -34
- package/lib/worker/worker.js.map +0 -1
- package/src/db/adapters/options.ts +0 -100
- package/src/db/adapters/resolveAndValidateOptions.ts +0 -40
- package/src/worker/SharedWorkerConnectionRequest.ts +0 -6
- package/src/worker/client.ts +0 -100
- package/src/worker/worker.ts +0 -38
- /package/dist/{worker/assets/mc-wa-sqlite-async-D6idQS2r.wasm → 2075a31bb151adbb9767.wasm} +0 -0
- /package/dist/{worker/assets/wa-sqlite-XZW__iJk.wasm → 3322bc84de986b63c2cd.wasm} +0 -0
- /package/dist/{worker/assets/mc-wa-sqlite-CnHbhWvs.wasm → 8e97452e297be23b5e50.wasm} +0 -0
- /package/dist/{worker/assets/wa-sqlite-async-rHzzC98y.wasm → fbc178b70d530e8ce02b.wasm} +0 -0
- /package/lib/{attachments → src/attachments}/IndexDBFileSystemAdapter.d.ts +0 -0
- /package/lib/{attachments → src/attachments}/IndexDBFileSystemAdapter.js +0 -0
- /package/lib/{db → src/db}/NavigatorTriggerClaimManager.js +0 -0
- /package/lib/{db → src/db}/adapters/WebDBAdapter.js +0 -0
- /package/lib/{db → src/db}/sync/userAgent.d.ts +0 -0
- /package/lib/{db → src/db}/sync/userAgent.js +0 -0
- /package/lib/{shared → src/shared}/navigator.d.ts +0 -0
- /package/lib/{shared → src/shared}/navigator.js +0 -0
- /package/lib/{shared → src/shared}/tab_close_signal.d.ts +0 -0
- /package/lib/{shared → src/shared}/tab_close_signal.js +0 -0
- /package/lib/{worker → src/worker}/sync/AbstractSharedSyncClientProvider.js +0 -0
- /package/lib/{worker/worker.d.ts → src/worker/sync/SharedSyncImplementation.worker.d.ts} +0 -0
|
@@ -1,39 +1,113 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ILogger, type ILogLevel, LogLevel } from '@powersync/common';
|
|
2
2
|
import { type WrappedSyncPort } from './SharedSyncImplementation.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Broadcasts logs to all clients
|
|
6
6
|
*/
|
|
7
|
-
export class BroadcastLogger implements
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
export class BroadcastLogger implements ILogger {
|
|
8
|
+
TRACE: ILogLevel;
|
|
9
|
+
DEBUG: ILogLevel;
|
|
10
|
+
INFO: ILogLevel;
|
|
11
|
+
TIME: ILogLevel;
|
|
12
|
+
WARN: ILogLevel;
|
|
13
|
+
ERROR: ILogLevel;
|
|
14
|
+
OFF: ILogLevel;
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
private currentLevel: ILogLevel = LogLevel.INFO;
|
|
12
17
|
|
|
13
|
-
constructor(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.
|
|
18
|
+
constructor(protected clients: WrappedSyncPort[]) {
|
|
19
|
+
this.TRACE = LogLevel.TRACE;
|
|
20
|
+
this.DEBUG = LogLevel.DEBUG;
|
|
21
|
+
this.INFO = LogLevel.INFO;
|
|
22
|
+
this.TIME = LogLevel.TIME;
|
|
23
|
+
this.WARN = LogLevel.WARN;
|
|
24
|
+
this.ERROR = LogLevel.ERROR;
|
|
25
|
+
this.OFF = LogLevel.OFF;
|
|
18
26
|
}
|
|
19
27
|
|
|
20
|
-
|
|
21
|
-
this.
|
|
28
|
+
trace(...x: any[]): void {
|
|
29
|
+
if (!this.enabledFor(this.TRACE)) return;
|
|
22
30
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
console.trace(...x);
|
|
32
|
+
const sanitized = this.sanitizeArgs(x);
|
|
33
|
+
this.iterateClients((client) => client.clientProvider.trace(...sanitized));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
debug(...x: any[]): void {
|
|
37
|
+
if (!this.enabledFor(this.DEBUG)) return;
|
|
38
|
+
|
|
39
|
+
console.debug(...x);
|
|
40
|
+
const sanitized = this.sanitizeArgs(x);
|
|
41
|
+
this.iterateClients((client) => client.clientProvider.debug(...sanitized));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
info(...x: any[]): void {
|
|
45
|
+
if (!this.enabledFor(this.INFO)) return;
|
|
46
|
+
|
|
47
|
+
console.info(...x);
|
|
48
|
+
const sanitized = this.sanitizeArgs(x);
|
|
49
|
+
this.iterateClients((client) => client.clientProvider.info(...sanitized));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
log(...x: any[]): void {
|
|
53
|
+
if (!this.enabledFor(this.INFO)) return;
|
|
54
|
+
|
|
55
|
+
console.log(...x);
|
|
56
|
+
const sanitized = this.sanitizeArgs(x);
|
|
57
|
+
this.iterateClients((client) => client.clientProvider.log(...sanitized));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
warn(...x: any[]): void {
|
|
61
|
+
if (!this.enabledFor(this.WARN)) return;
|
|
62
|
+
|
|
63
|
+
console.warn(...x);
|
|
64
|
+
const sanitized = this.sanitizeArgs(x);
|
|
65
|
+
this.iterateClients((client) => client.clientProvider.warn(...sanitized));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
error(...x: any[]): void {
|
|
69
|
+
if (!this.enabledFor(this.ERROR)) return;
|
|
70
|
+
|
|
71
|
+
console.error(...x);
|
|
72
|
+
const sanitized = this.sanitizeArgs(x);
|
|
73
|
+
this.iterateClients((client) => client.clientProvider.error(...sanitized));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
time(label: string): void {
|
|
77
|
+
if (!this.enabledFor(this.TIME)) return;
|
|
78
|
+
|
|
79
|
+
console.time(label);
|
|
80
|
+
this.iterateClients((client) => client.clientProvider.time(label));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
timeEnd(label: string): void {
|
|
84
|
+
if (!this.enabledFor(this.TIME)) return;
|
|
85
|
+
|
|
86
|
+
console.timeEnd(label);
|
|
87
|
+
this.iterateClients((client) => client.clientProvider.timeEnd(label));
|
|
27
88
|
}
|
|
28
89
|
|
|
29
90
|
/**
|
|
30
91
|
* Set the global log level.
|
|
31
92
|
*/
|
|
32
|
-
setLevel(level:
|
|
33
|
-
this.inner.minLevel = level;
|
|
93
|
+
setLevel(level: ILogLevel): void {
|
|
34
94
|
this.currentLevel = level;
|
|
35
95
|
}
|
|
36
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Get the current log level.
|
|
99
|
+
*/
|
|
100
|
+
getLevel(): ILogLevel {
|
|
101
|
+
return this.currentLevel;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Returns true if the given level is enabled.
|
|
106
|
+
*/
|
|
107
|
+
enabledFor(level: ILogLevel): boolean {
|
|
108
|
+
return level.value >= this.currentLevel.value;
|
|
109
|
+
}
|
|
110
|
+
|
|
37
111
|
/**
|
|
38
112
|
* Iterates all clients, catches individual client exceptions
|
|
39
113
|
* and proceeds to execute for all clients.
|
|
@@ -52,23 +126,17 @@ export class BroadcastLogger implements PowerSyncLogger {
|
|
|
52
126
|
* Guards against any logging errors.
|
|
53
127
|
* We don't want a logging exception to cause further issues upstream
|
|
54
128
|
*/
|
|
55
|
-
protected
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
console.error(ex);
|
|
66
|
-
error = 'Could not serialize log params. Check shared worker logs for more details.';
|
|
67
|
-
}
|
|
129
|
+
protected sanitizeArgs(x: any[]): any[] {
|
|
130
|
+
const sanitizedParams = x.map((param) => {
|
|
131
|
+
try {
|
|
132
|
+
// Try and clone here first. If it fails it won't be passable over a MessagePort
|
|
133
|
+
return structuredClone(param);
|
|
134
|
+
} catch (ex) {
|
|
135
|
+
console.error(ex);
|
|
136
|
+
return 'Could not serialize log params. Check shared worker logs for more details.';
|
|
137
|
+
}
|
|
138
|
+
});
|
|
68
139
|
|
|
69
|
-
return
|
|
70
|
-
...record,
|
|
71
|
-
error
|
|
72
|
-
};
|
|
140
|
+
return sanitizedParams;
|
|
73
141
|
}
|
|
74
142
|
}
|
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AbortOperation,
|
|
2
3
|
BaseObserver,
|
|
4
|
+
ConnectionManager,
|
|
5
|
+
ConnectionPool,
|
|
3
6
|
DBAdapter,
|
|
7
|
+
DBAdapterDefaultMixin,
|
|
8
|
+
DBAdapterListener,
|
|
4
9
|
DBLockOptions,
|
|
5
10
|
LockContext,
|
|
6
11
|
PowerSyncBackendConnector,
|
|
7
|
-
SyncStatus,
|
|
8
|
-
LogLevels,
|
|
9
|
-
SyncStreamConnectionMethod
|
|
10
|
-
} from '@powersync/common';
|
|
11
|
-
import {
|
|
12
|
-
AbortOperation,
|
|
13
|
-
ConnectionManager,
|
|
14
12
|
SqliteBucketStorage,
|
|
15
13
|
SubscribedStream,
|
|
14
|
+
SyncStatus,
|
|
15
|
+
createLogger,
|
|
16
|
+
Mutex,
|
|
17
|
+
type ILogLevel,
|
|
18
|
+
type ILogger,
|
|
19
|
+
type PowerSyncConnectionOptions,
|
|
16
20
|
type StreamingSyncImplementation,
|
|
17
21
|
type StreamingSyncImplementationListener,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
SyncStatusSnapshot
|
|
21
|
-
} from '@powersync/shared-internals';
|
|
22
|
+
type SyncStatusOptions
|
|
23
|
+
} from '@powersync/common';
|
|
22
24
|
import * as Comlink from 'comlink';
|
|
23
25
|
import { WebRemote } from '../../db/sync/WebRemote.js';
|
|
24
26
|
import {
|
|
@@ -26,11 +28,11 @@ import {
|
|
|
26
28
|
WebStreamingSyncImplementationOptions
|
|
27
29
|
} from '../../db/sync/WebStreamingSyncImplementation.js';
|
|
28
30
|
|
|
31
|
+
import { ResolvedWebSQLOpenOptions } from '../../db/adapters/web-sql-flags.js';
|
|
29
32
|
import { AbstractSharedSyncClientProvider } from './AbstractSharedSyncClientProvider.js';
|
|
30
33
|
import { BroadcastLogger } from './BroadcastLogger.js';
|
|
31
34
|
import { DatabaseClient, OpenWorkerConnection } from '../../db/adapters/wa-sqlite/DatabaseClient.js';
|
|
32
35
|
import { generateTabCloseSignal } from '../../shared/tab_close_signal.js';
|
|
33
|
-
import { ResolvedWebSQLOpenOptions } from '../../db/adapters/options.js';
|
|
34
36
|
|
|
35
37
|
/**
|
|
36
38
|
* @internal
|
|
@@ -58,12 +60,8 @@ export type ManualSharedSyncPayload = {
|
|
|
58
60
|
* @internal
|
|
59
61
|
*/
|
|
60
62
|
export type SharedSyncInitOptions = {
|
|
61
|
-
streamOptions: Omit<
|
|
62
|
-
WebStreamingSyncImplementationOptions,
|
|
63
|
-
'adapter' | 'uploadCrud' | 'remote' | 'subscriptions' | 'logger'
|
|
64
|
-
>;
|
|
63
|
+
streamOptions: Omit<WebStreamingSyncImplementationOptions, 'adapter' | 'uploadCrud' | 'remote' | 'subscriptions'>;
|
|
65
64
|
dbParams: ResolvedWebSQLOpenOptions;
|
|
66
|
-
enableBroadcastLogs: boolean;
|
|
67
65
|
};
|
|
68
66
|
|
|
69
67
|
/**
|
|
@@ -114,19 +112,21 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
114
112
|
protected uploadDataController?: RemoteOperationAbortController;
|
|
115
113
|
|
|
116
114
|
protected syncParams: SharedSyncInitOptions | null;
|
|
117
|
-
protected
|
|
115
|
+
protected logger: ILogger;
|
|
116
|
+
protected lastConnectOptions: PowerSyncConnectionOptions | undefined;
|
|
118
117
|
protected portMutex: Mutex;
|
|
119
118
|
private subscriptions: SubscribedStream[] = [];
|
|
120
119
|
|
|
121
120
|
protected connectionManager: ConnectionManager;
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
syncStatus: SyncStatus;
|
|
122
|
+
broadCastLogger: ILogger;
|
|
124
123
|
protected readonly database = this.generateReconnectableDatabase();
|
|
125
124
|
|
|
126
125
|
constructor() {
|
|
127
126
|
super();
|
|
128
127
|
this.ports = [];
|
|
129
128
|
this.syncParams = null;
|
|
129
|
+
this.logger = createLogger('shared-sync');
|
|
130
130
|
this.lastConnectOptions = undefined;
|
|
131
131
|
this.portMutex = new Mutex();
|
|
132
132
|
|
|
@@ -139,7 +139,8 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
139
139
|
});
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
-
this.
|
|
142
|
+
this.syncStatus = new SyncStatus({});
|
|
143
|
+
this.broadCastLogger = new BroadcastLogger(this.ports);
|
|
143
144
|
|
|
144
145
|
this.connectionManager = new ConnectionManager({
|
|
145
146
|
createSyncImplementation: async () => {
|
|
@@ -147,10 +148,8 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
147
148
|
|
|
148
149
|
const sync = this.generateStreamingImplementation();
|
|
149
150
|
const onDispose = sync.registerListener({
|
|
150
|
-
statusChanged: (
|
|
151
|
-
this.
|
|
152
|
-
const json = snapshot.toJSON();
|
|
153
|
-
this.ports.forEach((p) => p.clientProvider.statusChanged(json));
|
|
151
|
+
statusChanged: (status) => {
|
|
152
|
+
this.updateAllStatuses(status.toJSON());
|
|
154
153
|
}
|
|
155
154
|
});
|
|
156
155
|
|
|
@@ -159,8 +158,7 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
159
158
|
onDispose
|
|
160
159
|
};
|
|
161
160
|
},
|
|
162
|
-
logger: this.logger
|
|
163
|
-
defaultConnectionMethod: SyncStreamConnectionMethod.HTTP
|
|
161
|
+
logger: this.logger
|
|
164
162
|
});
|
|
165
163
|
}
|
|
166
164
|
|
|
@@ -194,6 +192,12 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
194
192
|
});
|
|
195
193
|
}
|
|
196
194
|
|
|
195
|
+
async waitForStatus(status: SyncStatusOptions): Promise<void> {
|
|
196
|
+
return this.withSyncImplementation(async (sync) => {
|
|
197
|
+
return sync.waitForStatus(status);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
197
201
|
async waitUntilStatusMatches(predicate: (status: SyncStatus) => boolean): Promise<void> {
|
|
198
202
|
return this.withSyncImplementation(async (sync) => {
|
|
199
203
|
return sync.waitUntilStatusMatches(predicate);
|
|
@@ -205,7 +209,7 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
205
209
|
}
|
|
206
210
|
|
|
207
211
|
private collectActiveSubscriptions() {
|
|
208
|
-
this.logger.
|
|
212
|
+
this.logger.debug('Collecting active stream subscriptions across tabs');
|
|
209
213
|
const active = new Map<string, SubscribedStream>();
|
|
210
214
|
for (const port of this.ports) {
|
|
211
215
|
for (const stream of port.currentSubscriptions) {
|
|
@@ -214,10 +218,7 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
214
218
|
}
|
|
215
219
|
}
|
|
216
220
|
this.subscriptions = [...active.values()];
|
|
217
|
-
this.logger.
|
|
218
|
-
level: LogLevels.debug,
|
|
219
|
-
message: `Collected stream subscriptions, ${JSON.stringify(this.subscriptions)}`
|
|
220
|
-
});
|
|
221
|
+
this.logger.debug('Collected stream subscriptions', this.subscriptions);
|
|
221
222
|
this.connectionManager.syncStreamImplementation?.updateSubscriptions(this.subscriptions);
|
|
222
223
|
}
|
|
223
224
|
|
|
@@ -226,8 +227,9 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
226
227
|
this.collectActiveSubscriptions();
|
|
227
228
|
}
|
|
228
229
|
|
|
229
|
-
setLogLevel(level:
|
|
230
|
+
setLogLevel(level: ILogLevel) {
|
|
230
231
|
this.logger.setLevel(level);
|
|
232
|
+
this.broadCastLogger.setLevel(level);
|
|
231
233
|
}
|
|
232
234
|
|
|
233
235
|
/**
|
|
@@ -245,18 +247,16 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
245
247
|
|
|
246
248
|
// First time setting params
|
|
247
249
|
this.syncParams = params;
|
|
248
|
-
|
|
250
|
+
if (params.streamOptions?.flags?.broadcastLogs) {
|
|
251
|
+
this.logger = this.broadCastLogger;
|
|
252
|
+
}
|
|
249
253
|
|
|
250
254
|
// Ensure we have a usable database connection, the reconnectable database will connect lazily on first use.
|
|
251
255
|
await this.database.readLock(async () => {});
|
|
252
256
|
|
|
253
257
|
self.onerror = (event) => {
|
|
254
258
|
// Share any uncaught events on the broadcast logger
|
|
255
|
-
this.logger.
|
|
256
|
-
level: LogLevels.error,
|
|
257
|
-
message: 'Uncaught exception in PowerSync shared sync worker',
|
|
258
|
-
error: event
|
|
259
|
-
});
|
|
259
|
+
this.logger.error('Uncaught exception in PowerSync shared sync worker', event);
|
|
260
260
|
};
|
|
261
261
|
|
|
262
262
|
this.iterateListeners((l) => l.initialized?.());
|
|
@@ -274,9 +274,9 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
274
274
|
* The connection will simply be reconnected whenever a new tab
|
|
275
275
|
* connects.
|
|
276
276
|
*/
|
|
277
|
-
async connect(options
|
|
277
|
+
async connect(options?: PowerSyncConnectionOptions) {
|
|
278
278
|
this.lastConnectOptions = options;
|
|
279
|
-
return this.connectionManager.connect(CONNECTOR_PLACEHOLDER, options ?? {}
|
|
279
|
+
return this.connectionManager.connect(CONNECTOR_PLACEHOLDER, options ?? {});
|
|
280
280
|
}
|
|
281
281
|
|
|
282
282
|
async disconnect() {
|
|
@@ -298,7 +298,7 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
298
298
|
this.ports.push(portProvider);
|
|
299
299
|
|
|
300
300
|
// Give the newly connected client the latest status
|
|
301
|
-
const status = this.syncStatus;
|
|
301
|
+
const status = this.connectionManager.syncStreamImplementation?.syncStatus;
|
|
302
302
|
if (status) {
|
|
303
303
|
portProvider.clientProvider.statusChanged(status.toJSON());
|
|
304
304
|
}
|
|
@@ -321,10 +321,7 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
321
321
|
return await this.portMutex.runExclusive(async () => {
|
|
322
322
|
const index = this.ports.findIndex((p) => p == port);
|
|
323
323
|
if (index < 0) {
|
|
324
|
-
this.logger.
|
|
325
|
-
level: LogLevels.warn,
|
|
326
|
-
message: `Could not remove port ${port} since it is not present in active ports.`
|
|
327
|
-
});
|
|
324
|
+
this.logger.warn(`Could not remove port ${port} since it is not present in active ports.`);
|
|
328
325
|
return () => {};
|
|
329
326
|
}
|
|
330
327
|
|
|
@@ -400,13 +397,10 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
400
397
|
throw new Error('No client port found to invalidate credentials');
|
|
401
398
|
}
|
|
402
399
|
try {
|
|
403
|
-
this.logger.log(
|
|
404
|
-
level: LogLevels.info,
|
|
405
|
-
message: 'calling the last port client provider to invalidate credentials'
|
|
406
|
-
});
|
|
400
|
+
this.logger.log('calling the last port client provider to invalidate credentials');
|
|
407
401
|
lastPort.clientProvider.invalidateCredentials();
|
|
408
|
-
} catch (
|
|
409
|
-
this.logger.
|
|
402
|
+
} catch (ex) {
|
|
403
|
+
this.logger.error('error invalidating credentials', ex);
|
|
410
404
|
}
|
|
411
405
|
},
|
|
412
406
|
fetchCredentials: async () => {
|
|
@@ -423,10 +417,7 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
423
417
|
|
|
424
418
|
abortController.signal.onabort = reject;
|
|
425
419
|
try {
|
|
426
|
-
this.logger.log(
|
|
427
|
-
level: LogLevels.info,
|
|
428
|
-
message: 'calling the last port client provider for credentials'
|
|
429
|
-
});
|
|
420
|
+
this.logger.log('calling the last port client provider for credentials');
|
|
430
421
|
resolve(await lastPort.clientProvider.fetchCredentials());
|
|
431
422
|
} catch (ex) {
|
|
432
423
|
reject(ex);
|
|
@@ -551,7 +542,7 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
551
542
|
clearTimeout(timeout);
|
|
552
543
|
|
|
553
544
|
client.closeListeners.push(async () => {
|
|
554
|
-
this.logger.
|
|
545
|
+
this.logger.info('Aborting open connection because associated tab closed.');
|
|
555
546
|
handleClosed(db);
|
|
556
547
|
/**
|
|
557
548
|
* Don't await this close operation. It might never resolve if the tab is closed.
|
|
@@ -559,9 +550,7 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
559
550
|
* We then call close. The close operation is configured to fire-and-forget, the main promise will reject immediately.
|
|
560
551
|
*/
|
|
561
552
|
db.markRemoteClosed();
|
|
562
|
-
db.close().catch((
|
|
563
|
-
this.logger.log({ level: LogLevels.warn, message: 'error closing database connection', error })
|
|
564
|
-
);
|
|
553
|
+
db.close().catch((ex) => this.logger.warn('error closing database connection', ex));
|
|
565
554
|
});
|
|
566
555
|
return db;
|
|
567
556
|
}
|
|
@@ -570,7 +559,7 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
570
559
|
const syncParams = this.syncParams;
|
|
571
560
|
const sharedSync = this;
|
|
572
561
|
|
|
573
|
-
|
|
562
|
+
class ReconnectPool extends BaseObserver<DBAdapterListener> implements ConnectionPool {
|
|
574
563
|
private connectionState:
|
|
575
564
|
| null
|
|
576
565
|
| DatabaseClient<ResolvedWebSQLOpenOptions>
|
|
@@ -639,7 +628,19 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
639
628
|
async refreshSchema(): Promise<void> {
|
|
640
629
|
// Not used by sync client.
|
|
641
630
|
}
|
|
642
|
-
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
const Adapter = DBAdapterDefaultMixin(ReconnectPool);
|
|
634
|
+
return new Adapter();
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* A method to update the all shared statuses for each
|
|
639
|
+
* client.
|
|
640
|
+
*/
|
|
641
|
+
private updateAllStatuses(status: SyncStatusOptions) {
|
|
642
|
+
this.syncStatus = new SyncStatus(status);
|
|
643
|
+
this.ports.forEach((p) => p.clientProvider.statusChanged(status));
|
|
643
644
|
}
|
|
644
645
|
}
|
|
645
646
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createBaseLogger } from '@powersync/common';
|
|
2
|
+
import { SharedSyncImplementation } from './SharedSyncImplementation.js';
|
|
3
|
+
import { WorkerClient } from './WorkerClient.js';
|
|
4
|
+
|
|
5
|
+
const _self: SharedWorkerGlobalScope = self as any;
|
|
6
|
+
const logger = createBaseLogger();
|
|
7
|
+
logger.useDefaults();
|
|
8
|
+
|
|
9
|
+
const sharedSyncImplementation = new SharedSyncImplementation();
|
|
10
|
+
|
|
11
|
+
_self.onconnect = async function (event: MessageEvent<string>) {
|
|
12
|
+
const port = event.ports[0];
|
|
13
|
+
new WorkerClient(sharedSyncImplementation, port);
|
|
14
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ILogLevel, PowerSyncConnectionOptions, SubscribedStream } from '@powersync/common';
|
|
1
2
|
import * as Comlink from 'comlink';
|
|
2
3
|
import { getNavigatorLocks } from '../../shared/navigator.js';
|
|
3
4
|
import {
|
|
@@ -7,7 +8,6 @@ import {
|
|
|
7
8
|
SharedSyncInitOptions,
|
|
8
9
|
WrappedSyncPort
|
|
9
10
|
} from './SharedSyncImplementation.js';
|
|
10
|
-
import { SubscribedStream, ResolvedSyncOptions } from '@powersync/shared-internals';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* A client to the shared sync worker.
|
|
@@ -65,7 +65,7 @@ export class WorkerClient {
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
setLogLevel(level:
|
|
68
|
+
setLogLevel(level: ILogLevel) {
|
|
69
69
|
this.sync.setLogLevel(level);
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -82,8 +82,8 @@ export class WorkerClient {
|
|
|
82
82
|
return this.sync.getWriteCheckpoint();
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
connect(options
|
|
86
|
-
return this.sync.connect(options
|
|
85
|
+
connect(options?: PowerSyncConnectionOptions) {
|
|
86
|
+
return this.sync.connect(options);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
updateSubscriptions(subscriptions: SubscribedStream[]) {
|