@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,145 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@powersync/common';
|
|
2
|
-
import * as Comlink from 'comlink';
|
|
3
|
-
import { openWorkerDatabasePort, resolveWorkerDatabasePortFactory } from '../../../worker/db/open-worker-database.js';
|
|
4
|
-
import { DEFAULT_CACHE_SIZE_KB, isServerSide, resolveWebSQLFlags, TemporaryStorageOption } from '../web-sql-flags.js';
|
|
5
|
-
import { SSRDBAdapter } from '../SSRDBAdapter.js';
|
|
6
|
-
import { vfsRequiresDedicatedWorkers, WASQLiteVFS } from './vfs.js';
|
|
7
|
-
import { MultiDatabaseServer } from '../../../worker/db/MultiDatabaseServer.js';
|
|
8
|
-
import { DatabaseClient } from './DatabaseClient.js';
|
|
9
|
-
import { generateTabCloseSignal } from '../../../shared/tab_close_signal.js';
|
|
10
|
-
import { AsyncDbAdapter } from '../AsyncWebAdapter.js';
|
|
11
|
-
/**
|
|
12
|
-
* Opens a SQLite connection using WA-SQLite.
|
|
13
|
-
*/
|
|
14
|
-
export class WASQLiteOpenFactory {
|
|
15
|
-
options;
|
|
16
|
-
resolvedFlags;
|
|
17
|
-
logger;
|
|
18
|
-
constructor(options) {
|
|
19
|
-
this.options = options;
|
|
20
|
-
assertValidWASQLiteOpenFactoryOptions(options);
|
|
21
|
-
this.resolvedFlags = resolveWebSQLFlags(options.flags);
|
|
22
|
-
this.logger = options.logger ?? createLogger(`WASQLiteOpenFactory - ${this.options.dbFilename}`);
|
|
23
|
-
}
|
|
24
|
-
get waOptions() {
|
|
25
|
-
// Cast to extended type
|
|
26
|
-
return this.options;
|
|
27
|
-
}
|
|
28
|
-
openAdapter() {
|
|
29
|
-
return new AsyncDbAdapter(this.openConnection(), this.options.dbFilename);
|
|
30
|
-
}
|
|
31
|
-
openDB() {
|
|
32
|
-
const { resolvedFlags: { disableSSRWarning, enableMultiTabs, ssrMode = isServerSide() } } = this;
|
|
33
|
-
if (ssrMode) {
|
|
34
|
-
if (!disableSSRWarning) {
|
|
35
|
-
this.logger.warn(`
|
|
36
|
-
Running PowerSync in SSR mode.
|
|
37
|
-
Only empty query results will be returned.
|
|
38
|
-
Disable this warning by setting 'disableSSRWarning: true' in options.`);
|
|
39
|
-
}
|
|
40
|
-
return new SSRDBAdapter();
|
|
41
|
-
}
|
|
42
|
-
if (!enableMultiTabs) {
|
|
43
|
-
this.logger.warn('Multiple tab support is not enabled. Using this site across multiple tabs may not function correctly.');
|
|
44
|
-
}
|
|
45
|
-
return this.openAdapter();
|
|
46
|
-
}
|
|
47
|
-
async openConnection() {
|
|
48
|
-
const { enableMultiTabs, useWebWorker } = this.resolvedFlags;
|
|
49
|
-
const { vfs = WASQLiteVFS.IDBBatchAtomicVFS, temporaryStorage = TemporaryStorageOption.MEMORY, cacheSizeKb = DEFAULT_CACHE_SIZE_KB, encryptionKey } = this.waOptions;
|
|
50
|
-
if (!enableMultiTabs) {
|
|
51
|
-
this.logger.warn('Multiple tabs are not enabled in this browser');
|
|
52
|
-
}
|
|
53
|
-
const resolveOptions = (isReadOnly) => ({
|
|
54
|
-
dbFilename: this.options.dbFilename,
|
|
55
|
-
dbLocation: this.options.dbLocation,
|
|
56
|
-
debugMode: this.options.debugMode,
|
|
57
|
-
vfs,
|
|
58
|
-
temporaryStorage,
|
|
59
|
-
cacheSizeKb,
|
|
60
|
-
flags: this.resolvedFlags,
|
|
61
|
-
encryptionKey: encryptionKey,
|
|
62
|
-
isReadOnly
|
|
63
|
-
});
|
|
64
|
-
let client;
|
|
65
|
-
let additionalReaders = [];
|
|
66
|
-
let requiresPersistentTriggers = vfsRequiresDedicatedWorkers(vfs);
|
|
67
|
-
if (useWebWorker) {
|
|
68
|
-
const optionsDbWorker = this.options.worker;
|
|
69
|
-
const openDatabaseWorker = async (resolvedOptions) => {
|
|
70
|
-
const workerPort = typeof optionsDbWorker == 'function'
|
|
71
|
-
? resolveWorkerDatabasePortFactory(() => optionsDbWorker({
|
|
72
|
-
...this.options,
|
|
73
|
-
temporaryStorage,
|
|
74
|
-
cacheSizeKb,
|
|
75
|
-
flags: this.resolvedFlags,
|
|
76
|
-
encryptionKey
|
|
77
|
-
}))
|
|
78
|
-
: openWorkerDatabasePort(this.options.dbFilename, enableMultiTabs, optionsDbWorker, this.waOptions.vfs);
|
|
79
|
-
const source = Comlink.wrap(workerPort);
|
|
80
|
-
const closeSignal = new AbortController();
|
|
81
|
-
const connection = await source.connect({
|
|
82
|
-
...resolvedOptions,
|
|
83
|
-
logLevel: this.logger.getLevel(),
|
|
84
|
-
lockName: await generateTabCloseSignal(closeSignal.signal)
|
|
85
|
-
});
|
|
86
|
-
const clientOptions = {
|
|
87
|
-
connection,
|
|
88
|
-
source,
|
|
89
|
-
// This tab owns the worker, so we're guaranteed to outlive it.
|
|
90
|
-
remoteCanCloseUnexpectedly: false,
|
|
91
|
-
onClose: () => {
|
|
92
|
-
closeSignal.abort();
|
|
93
|
-
if (workerPort instanceof Worker) {
|
|
94
|
-
workerPort.terminate();
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
workerPort.close();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
return new DatabaseClient(clientOptions, {
|
|
102
|
-
...resolvedOptions,
|
|
103
|
-
requiresPersistentTriggers
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
client = await openDatabaseWorker(resolveOptions(false));
|
|
107
|
-
if (vfs == WASQLiteVFS.OPFSWriteAheadVFS) {
|
|
108
|
-
// This VFS supports concurrent reads, so we can open additional workers to host read-only connections for
|
|
109
|
-
// concurrent reads / writes.
|
|
110
|
-
const additionalReadersCount = this.options.additionalReaders ?? 1;
|
|
111
|
-
for (let i = 0; i < additionalReadersCount; i++) {
|
|
112
|
-
const reader = await openDatabaseWorker(resolveOptions(true));
|
|
113
|
-
additionalReaders.push(reader);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
// Don't use a web worker. Instead, open the MultiDatabaseServer a worker would use locally.
|
|
119
|
-
const localServer = new MultiDatabaseServer(this.logger);
|
|
120
|
-
requiresPersistentTriggers = true;
|
|
121
|
-
const resolvedOptions = resolveOptions(false);
|
|
122
|
-
const connection = await localServer.openConnectionLocally(resolvedOptions);
|
|
123
|
-
client = new DatabaseClient({ connection, source: null, remoteCanCloseUnexpectedly: false }, {
|
|
124
|
-
...resolvedOptions,
|
|
125
|
-
requiresPersistentTriggers
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
return {
|
|
129
|
-
writer: client,
|
|
130
|
-
additionalReaders
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Asserts that the factory options are valid.
|
|
136
|
-
*/
|
|
137
|
-
function assertValidWASQLiteOpenFactoryOptions(options) {
|
|
138
|
-
// The OPFS VFS only works in dedicated web workers.
|
|
139
|
-
if ('vfs' in options && 'flags' in options) {
|
|
140
|
-
const { vfs, flags = {} } = options;
|
|
141
|
-
if (vfs && vfsRequiresDedicatedWorkers(vfs) && 'useWebWorker' in flags && !flags.useWebWorker) {
|
|
142
|
-
throw new Error(`Invalid configuration: The 'useWebWorker' flag must be true when using an OPFS-based VFS (${vfs}).`);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { AbstractPowerSyncDatabase, DBAdapter, PowerSyncDatabaseOptions } from '@powersync/common';
|
|
2
|
-
import { AbstractWebPowerSyncDatabaseOpenFactory } from '../AbstractWebPowerSyncDatabaseOpenFactory.js';
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated {@link PowerSyncDatabase} can now be constructed directly
|
|
5
|
-
* @example
|
|
6
|
-
* ```typescript
|
|
7
|
-
* const powersync = new PowerSyncDatabase({database: {
|
|
8
|
-
* dbFileName: 'powersync.db'
|
|
9
|
-
* }});
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export declare class WASQLitePowerSyncDatabaseOpenFactory extends AbstractWebPowerSyncDatabaseOpenFactory {
|
|
13
|
-
protected openDB(): DBAdapter;
|
|
14
|
-
generateInstance(options: PowerSyncDatabaseOptions): AbstractPowerSyncDatabase;
|
|
15
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { PowerSyncDatabase } from '../../../db/PowerSyncDatabase.js';
|
|
2
|
-
import { AbstractWebPowerSyncDatabaseOpenFactory } from '../AbstractWebPowerSyncDatabaseOpenFactory.js';
|
|
3
|
-
import { WASQLiteOpenFactory } from './WASQLiteOpenFactory.js';
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated {@link PowerSyncDatabase} can now be constructed directly
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* const powersync = new PowerSyncDatabase({database: {
|
|
9
|
-
* dbFileName: 'powersync.db'
|
|
10
|
-
* }});
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
export class WASQLitePowerSyncDatabaseOpenFactory extends AbstractWebPowerSyncDatabaseOpenFactory {
|
|
14
|
-
openDB() {
|
|
15
|
-
const factory = new WASQLiteOpenFactory(this.options);
|
|
16
|
-
return factory.openDB();
|
|
17
|
-
}
|
|
18
|
-
generateInstance(options) {
|
|
19
|
-
return new PowerSyncDatabase(options);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { type ILogger, SQLOpenOptions } from '@powersync/common';
|
|
2
|
-
/**
|
|
3
|
-
* Common settings used when creating SQL connections on web.
|
|
4
|
-
*/
|
|
5
|
-
export interface WebSQLFlags {
|
|
6
|
-
/**
|
|
7
|
-
* Broadcast logs from shared workers, such as the shared sync worker,
|
|
8
|
-
* to individual tabs. This defaults to true.
|
|
9
|
-
*/
|
|
10
|
-
broadcastLogs?: boolean;
|
|
11
|
-
/**
|
|
12
|
-
* SQLite operations are currently not supported in SSR mode.
|
|
13
|
-
* A warning will be logged if attempting to use SQLite in SSR.
|
|
14
|
-
* Setting this to `true` will disabled the warning above.
|
|
15
|
-
*/
|
|
16
|
-
disableSSRWarning?: boolean;
|
|
17
|
-
/**
|
|
18
|
-
* Enables multi tab support
|
|
19
|
-
*/
|
|
20
|
-
enableMultiTabs?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* The SQLite connection is often executed through a web worker
|
|
23
|
-
* in order to offload computation. This can be used to manually
|
|
24
|
-
* disable the use of web workers in environments where web workers
|
|
25
|
-
* might be unstable.
|
|
26
|
-
*/
|
|
27
|
-
useWebWorker?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Open in SSR placeholder mode. DB operations and Sync operations will be a No-op
|
|
30
|
-
*/
|
|
31
|
-
ssrMode?: boolean;
|
|
32
|
-
}
|
|
33
|
-
export type ResolvedWebSQLFlags = Required<WebSQLFlags>;
|
|
34
|
-
export interface ResolvedWebSQLOpenOptions extends SQLOpenOptions {
|
|
35
|
-
flags: ResolvedWebSQLFlags;
|
|
36
|
-
/**
|
|
37
|
-
* Where to store SQLite temporary files. Defaults to 'MEMORY'.
|
|
38
|
-
* Setting this to `FILESYSTEM` can cause issues with larger queries or datasets.
|
|
39
|
-
*/
|
|
40
|
-
temporaryStorage: TemporaryStorageOption;
|
|
41
|
-
cacheSizeKb: number;
|
|
42
|
-
/**
|
|
43
|
-
* Encryption key for the database.
|
|
44
|
-
* If set, the database will be encrypted using ChaCha20.
|
|
45
|
-
*/
|
|
46
|
-
encryptionKey?: string;
|
|
47
|
-
}
|
|
48
|
-
export declare enum TemporaryStorageOption {
|
|
49
|
-
MEMORY = "memory",
|
|
50
|
-
FILESYSTEM = "file"
|
|
51
|
-
}
|
|
52
|
-
export declare const DEFAULT_CACHE_SIZE_KB: number;
|
|
53
|
-
/**
|
|
54
|
-
* Options for opening a Web SQL connection
|
|
55
|
-
*/
|
|
56
|
-
export interface WebSQLOpenFactoryOptions extends SQLOpenOptions {
|
|
57
|
-
flags?: WebSQLFlags;
|
|
58
|
-
/**
|
|
59
|
-
* Allows you to override the default wasqlite db worker.
|
|
60
|
-
*
|
|
61
|
-
* You can either provide a path to the worker script
|
|
62
|
-
* or a factory method that returns a worker.
|
|
63
|
-
*/
|
|
64
|
-
worker?: string | URL | ((options: ResolvedWebSQLOpenOptions) => Worker | SharedWorker);
|
|
65
|
-
/**
|
|
66
|
-
* Use an existing port to an initialized worker.
|
|
67
|
-
* A worker will be initialized if none is provided
|
|
68
|
-
*/
|
|
69
|
-
workerPort?: MessagePort;
|
|
70
|
-
logger?: ILogger;
|
|
71
|
-
/**
|
|
72
|
-
* Where to store SQLite temporary files. Defaults to 'MEMORY'.
|
|
73
|
-
* Setting this to `FILESYSTEM` can cause issues with larger queries or datasets.
|
|
74
|
-
*
|
|
75
|
-
* For details, see: https://www.sqlite.org/pragma.html#pragma_temp_store
|
|
76
|
-
*/
|
|
77
|
-
temporaryStorage?: TemporaryStorageOption;
|
|
78
|
-
/**
|
|
79
|
-
* Maximum SQLite cache size. Defaults to 50MB.
|
|
80
|
-
*
|
|
81
|
-
* For details, see: https://www.sqlite.org/pragma.html#pragma_cache_size
|
|
82
|
-
*/
|
|
83
|
-
cacheSizeKb?: number;
|
|
84
|
-
/**
|
|
85
|
-
* Encryption key for the database.
|
|
86
|
-
* If set, the database will be encrypted using ChaCha20.
|
|
87
|
-
*/
|
|
88
|
-
encryptionKey?: string;
|
|
89
|
-
}
|
|
90
|
-
export declare function isServerSide(): boolean;
|
|
91
|
-
export declare const DEFAULT_WEB_SQL_FLAGS: ResolvedWebSQLFlags;
|
|
92
|
-
export declare function resolveWebSQLFlags(flags?: WebSQLFlags): ResolvedWebSQLFlags;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export var TemporaryStorageOption;
|
|
2
|
-
(function (TemporaryStorageOption) {
|
|
3
|
-
TemporaryStorageOption["MEMORY"] = "memory";
|
|
4
|
-
TemporaryStorageOption["FILESYSTEM"] = "file";
|
|
5
|
-
})(TemporaryStorageOption || (TemporaryStorageOption = {}));
|
|
6
|
-
export const DEFAULT_CACHE_SIZE_KB = 50 * 1024;
|
|
7
|
-
export function isServerSide() {
|
|
8
|
-
return typeof window == 'undefined';
|
|
9
|
-
}
|
|
10
|
-
export const DEFAULT_WEB_SQL_FLAGS = {
|
|
11
|
-
broadcastLogs: true,
|
|
12
|
-
disableSSRWarning: false,
|
|
13
|
-
ssrMode: isServerSide(),
|
|
14
|
-
/**
|
|
15
|
-
* Multiple tabs are by default not supported on Android, iOS and Safari.
|
|
16
|
-
* Other platforms will have multiple tabs enabled by default.
|
|
17
|
-
*/
|
|
18
|
-
enableMultiTabs: typeof globalThis.navigator !== 'undefined' && // For SSR purposes
|
|
19
|
-
typeof SharedWorker !== 'undefined' &&
|
|
20
|
-
!navigator.userAgent.match(/(Android|iPhone|iPod|iPad)/i) &&
|
|
21
|
-
!window.safari,
|
|
22
|
-
useWebWorker: true
|
|
23
|
-
};
|
|
24
|
-
export function resolveWebSQLFlags(flags) {
|
|
25
|
-
const resolvedFlags = {
|
|
26
|
-
...DEFAULT_WEB_SQL_FLAGS,
|
|
27
|
-
...(flags ?? {})
|
|
28
|
-
};
|
|
29
|
-
if (typeof flags?.enableMultiTabs != 'undefined') {
|
|
30
|
-
resolvedFlags.enableMultiTabs = flags.enableMultiTabs;
|
|
31
|
-
}
|
|
32
|
-
if (flags?.useWebWorker === false) {
|
|
33
|
-
resolvedFlags.enableMultiTabs = false;
|
|
34
|
-
}
|
|
35
|
-
return resolvedFlags;
|
|
36
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AbstractRemote, AbstractRemoteOptions, ILogger, RemoteConnector } from '@powersync/common';
|
|
2
|
-
export declare class WebRemote extends AbstractRemote {
|
|
3
|
-
protected connector: RemoteConnector;
|
|
4
|
-
protected logger: ILogger;
|
|
5
|
-
constructor(connector: RemoteConnector, logger?: ILogger, options?: Partial<AbstractRemoteOptions>);
|
|
6
|
-
getUserAgent(): string;
|
|
7
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { AbstractRemote, DEFAULT_REMOTE_LOGGER, FetchImplementationProvider } from '@powersync/common';
|
|
2
|
-
import { getUserAgentInfo } from './userAgent.js';
|
|
3
|
-
/*
|
|
4
|
-
* Depends on browser's implementation of global fetch.
|
|
5
|
-
*/
|
|
6
|
-
class WebFetchProvider extends FetchImplementationProvider {
|
|
7
|
-
getFetch() {
|
|
8
|
-
return fetch.bind(globalThis);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export class WebRemote extends AbstractRemote {
|
|
12
|
-
connector;
|
|
13
|
-
logger;
|
|
14
|
-
constructor(connector, logger = DEFAULT_REMOTE_LOGGER, options) {
|
|
15
|
-
super(connector, logger, {
|
|
16
|
-
...(options ?? {}),
|
|
17
|
-
fetchImplementation: options?.fetchImplementation ?? new WebFetchProvider()
|
|
18
|
-
});
|
|
19
|
-
this.connector = connector;
|
|
20
|
-
this.logger = logger;
|
|
21
|
-
}
|
|
22
|
-
getUserAgent() {
|
|
23
|
-
let ua = [super.getUserAgent(), `powersync-web`];
|
|
24
|
-
try {
|
|
25
|
-
ua.push(...getUserAgentInfo());
|
|
26
|
-
}
|
|
27
|
-
catch (e) {
|
|
28
|
-
this.logger.warn('Failed to get user agent info', e);
|
|
29
|
-
}
|
|
30
|
-
return ua.join(' ');
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ILogger } from '@powersync/common';
|
|
2
|
-
import { ClientConnectionView } from '../../db/adapters/wa-sqlite/DatabaseServer.js';
|
|
3
|
-
import { ResolvedWASQLiteOpenFactoryOptions, WorkerDBOpenerOptions } from '../../db/adapters/wa-sqlite/WASQLiteOpenFactory.js';
|
|
4
|
-
/**
|
|
5
|
-
* Shared state to manage multiple database connections hosted by a worker.
|
|
6
|
-
*/
|
|
7
|
-
export declare class MultiDatabaseServer {
|
|
8
|
-
readonly logger: ILogger;
|
|
9
|
-
private activeDatabases;
|
|
10
|
-
constructor(logger: ILogger);
|
|
11
|
-
handleConnection(options: WorkerDBOpenerOptions): Promise<ClientConnectionView>;
|
|
12
|
-
connectToExisting(name: string, lockName: string): Promise<ClientConnectionView>;
|
|
13
|
-
openConnectionLocally(options: ResolvedWASQLiteOpenFactoryOptions, lockName?: string): Promise<ClientConnectionView>;
|
|
14
|
-
private databaseOpenAttempt;
|
|
15
|
-
closeAll(): Promise<void[]>;
|
|
16
|
-
}
|
|
17
|
-
export declare const isSharedWorker: boolean;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Supports both shared and dedicated workers, based on how the worker is constructed (new SharedWorker vs new Worker()).
|
|
3
|
-
*/
|
|
4
|
-
import '@journeyapps/wa-sqlite';
|
|
5
|
-
import { createBaseLogger, createLogger } from '@powersync/common';
|
|
6
|
-
import * as Comlink from 'comlink';
|
|
7
|
-
import { isSharedWorker, MultiDatabaseServer } from './MultiDatabaseServer.js';
|
|
8
|
-
const baseLogger = createBaseLogger();
|
|
9
|
-
baseLogger.useDefaults();
|
|
10
|
-
const logger = createLogger('db-worker');
|
|
11
|
-
const server = new MultiDatabaseServer(logger);
|
|
12
|
-
const exposedFunctions = {
|
|
13
|
-
connect: (config) => server.handleConnection(config),
|
|
14
|
-
connectToExisting: ({ identifier, lockName }) => server.connectToExisting(identifier, lockName)
|
|
15
|
-
};
|
|
16
|
-
// Check if we're in a SharedWorker context
|
|
17
|
-
if (isSharedWorker) {
|
|
18
|
-
const _self = self;
|
|
19
|
-
_self.onconnect = function (event) {
|
|
20
|
-
const port = event.ports[0];
|
|
21
|
-
Comlink.expose(exposedFunctions, port);
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
// A dedicated worker can be shared externally
|
|
26
|
-
Comlink.expose(exposedFunctions);
|
|
27
|
-
}
|
|
28
|
-
addEventListener('unload', () => {
|
|
29
|
-
server.closeAll();
|
|
30
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as Comlink from 'comlink';
|
|
2
|
-
import { WASQLiteVFS } from '../../db/adapters/wa-sqlite/vfs.js';
|
|
3
|
-
import { OpenWorkerConnection } from '../../db/adapters/wa-sqlite/DatabaseClient.js';
|
|
4
|
-
/**
|
|
5
|
-
* Opens a shared or dedicated worker which exposes opening of database connections
|
|
6
|
-
*/
|
|
7
|
-
export declare function openWorkerDatabasePort(workerIdentifier: string, multipleTabs?: boolean, worker?: string | URL, vfs?: WASQLiteVFS): Worker | MessagePort;
|
|
8
|
-
/**
|
|
9
|
-
* @returns A function which allows for opening database connections inside
|
|
10
|
-
* a worker.
|
|
11
|
-
*/
|
|
12
|
-
export declare function getWorkerDatabaseOpener(workerIdentifier: string, multipleTabs?: boolean, worker?: string | URL): Comlink.Remote<OpenWorkerConnection>;
|
|
13
|
-
export declare function resolveWorkerDatabasePortFactory(worker: () => Worker | SharedWorker): Worker | MessagePort;
|
|
14
|
-
export declare function isSharedWorker(worker: Worker | SharedWorker): worker is SharedWorker;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import * as Comlink from 'comlink';
|
|
2
|
-
import { vfsRequiresDedicatedWorkers } from '../../db/adapters/wa-sqlite/vfs.js';
|
|
3
|
-
/**
|
|
4
|
-
* Opens a shared or dedicated worker which exposes opening of database connections
|
|
5
|
-
*/
|
|
6
|
-
export function openWorkerDatabasePort(workerIdentifier, multipleTabs = true, worker = '', vfs) {
|
|
7
|
-
const needsDedicated = vfs && vfsRequiresDedicatedWorkers(vfs);
|
|
8
|
-
if (worker) {
|
|
9
|
-
return !needsDedicated && multipleTabs
|
|
10
|
-
? new SharedWorker(`${worker}`, {
|
|
11
|
-
/* @vite-ignore */
|
|
12
|
-
name: `shared-DB-worker-${workerIdentifier}`
|
|
13
|
-
}).port
|
|
14
|
-
: new Worker(`${worker}`, {
|
|
15
|
-
/* @vite-ignore */
|
|
16
|
-
name: `DB-worker-${workerIdentifier}`
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
/**
|
|
21
|
-
* Webpack V5 can bundle the worker automatically if the full Worker constructor syntax is used
|
|
22
|
-
* https://webpack.js.org/guides/web-workers/
|
|
23
|
-
* This enables multi tab support by default, but falls back if SharedWorker is not available
|
|
24
|
-
* (in the case of Android)
|
|
25
|
-
*/
|
|
26
|
-
return !needsDedicated && multipleTabs
|
|
27
|
-
? new SharedWorker(new URL('./WASQLiteDB.worker.js', import.meta.url), {
|
|
28
|
-
/* @vite-ignore */
|
|
29
|
-
name: `shared-DB-worker-${workerIdentifier}`,
|
|
30
|
-
type: 'module'
|
|
31
|
-
}).port
|
|
32
|
-
: new Worker(new URL('./WASQLiteDB.worker.js', import.meta.url), {
|
|
33
|
-
/* @vite-ignore */
|
|
34
|
-
name: `DB-worker-${workerIdentifier}`,
|
|
35
|
-
type: 'module'
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* @returns A function which allows for opening database connections inside
|
|
41
|
-
* a worker.
|
|
42
|
-
*/
|
|
43
|
-
export function getWorkerDatabaseOpener(workerIdentifier, multipleTabs = true, worker = '') {
|
|
44
|
-
return Comlink.wrap(openWorkerDatabasePort(workerIdentifier, multipleTabs, worker));
|
|
45
|
-
}
|
|
46
|
-
export function resolveWorkerDatabasePortFactory(worker) {
|
|
47
|
-
const workerInstance = worker();
|
|
48
|
-
return isSharedWorker(workerInstance) ? workerInstance.port : workerInstance;
|
|
49
|
-
}
|
|
50
|
-
export function isSharedWorker(worker) {
|
|
51
|
-
return 'port' in worker;
|
|
52
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { PowerSyncCredentials, SyncStatusOptions } from '@powersync/common';
|
|
2
|
-
/**
|
|
3
|
-
* The client side port should provide these methods.
|
|
4
|
-
*/
|
|
5
|
-
export declare abstract class AbstractSharedSyncClientProvider {
|
|
6
|
-
abstract fetchCredentials(): Promise<PowerSyncCredentials | null>;
|
|
7
|
-
abstract invalidateCredentials(): void;
|
|
8
|
-
abstract uploadCrud(): Promise<void>;
|
|
9
|
-
abstract statusChanged(status: SyncStatusOptions): void;
|
|
10
|
-
abstract getDBWorkerPort(): Promise<MessagePort>;
|
|
11
|
-
abstract trace(...x: any[]): void;
|
|
12
|
-
abstract debug(...x: any[]): void;
|
|
13
|
-
abstract info(...x: any[]): void;
|
|
14
|
-
abstract log(...x: any[]): void;
|
|
15
|
-
abstract warn(...x: any[]): void;
|
|
16
|
-
abstract error(...x: any[]): void;
|
|
17
|
-
abstract time(label: string): void;
|
|
18
|
-
abstract timeEnd(label: string): void;
|
|
19
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { type ILogger, type ILogLevel } from '@powersync/common';
|
|
2
|
-
import { type WrappedSyncPort } from './SharedSyncImplementation.js';
|
|
3
|
-
/**
|
|
4
|
-
* Broadcasts logs to all clients
|
|
5
|
-
*/
|
|
6
|
-
export declare class BroadcastLogger implements ILogger {
|
|
7
|
-
protected clients: WrappedSyncPort[];
|
|
8
|
-
TRACE: ILogLevel;
|
|
9
|
-
DEBUG: ILogLevel;
|
|
10
|
-
INFO: ILogLevel;
|
|
11
|
-
TIME: ILogLevel;
|
|
12
|
-
WARN: ILogLevel;
|
|
13
|
-
ERROR: ILogLevel;
|
|
14
|
-
OFF: ILogLevel;
|
|
15
|
-
private currentLevel;
|
|
16
|
-
constructor(clients: WrappedSyncPort[]);
|
|
17
|
-
trace(...x: any[]): void;
|
|
18
|
-
debug(...x: any[]): void;
|
|
19
|
-
info(...x: any[]): void;
|
|
20
|
-
log(...x: any[]): void;
|
|
21
|
-
warn(...x: any[]): void;
|
|
22
|
-
error(...x: any[]): void;
|
|
23
|
-
time(label: string): void;
|
|
24
|
-
timeEnd(label: string): void;
|
|
25
|
-
/**
|
|
26
|
-
* Set the global log level.
|
|
27
|
-
*/
|
|
28
|
-
setLevel(level: ILogLevel): void;
|
|
29
|
-
/**
|
|
30
|
-
* Get the current log level.
|
|
31
|
-
*/
|
|
32
|
-
getLevel(): ILogLevel;
|
|
33
|
-
/**
|
|
34
|
-
* Returns true if the given level is enabled.
|
|
35
|
-
*/
|
|
36
|
-
enabledFor(level: ILogLevel): boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Iterates all clients, catches individual client exceptions
|
|
39
|
-
* and proceeds to execute for all clients.
|
|
40
|
-
*/
|
|
41
|
-
protected iterateClients(callback: (client: WrappedSyncPort) => Promise<void>): Promise<void>;
|
|
42
|
-
/**
|
|
43
|
-
* Guards against any logging errors.
|
|
44
|
-
* We don't want a logging exception to cause further issues upstream
|
|
45
|
-
*/
|
|
46
|
-
protected sanitizeArgs(x: any[]): any[];
|
|
47
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { LogLevel } from '@powersync/common';
|
|
2
|
-
/**
|
|
3
|
-
* Broadcasts logs to all clients
|
|
4
|
-
*/
|
|
5
|
-
export class BroadcastLogger {
|
|
6
|
-
clients;
|
|
7
|
-
TRACE;
|
|
8
|
-
DEBUG;
|
|
9
|
-
INFO;
|
|
10
|
-
TIME;
|
|
11
|
-
WARN;
|
|
12
|
-
ERROR;
|
|
13
|
-
OFF;
|
|
14
|
-
currentLevel = LogLevel.INFO;
|
|
15
|
-
constructor(clients) {
|
|
16
|
-
this.clients = clients;
|
|
17
|
-
this.TRACE = LogLevel.TRACE;
|
|
18
|
-
this.DEBUG = LogLevel.DEBUG;
|
|
19
|
-
this.INFO = LogLevel.INFO;
|
|
20
|
-
this.TIME = LogLevel.TIME;
|
|
21
|
-
this.WARN = LogLevel.WARN;
|
|
22
|
-
this.ERROR = LogLevel.ERROR;
|
|
23
|
-
this.OFF = LogLevel.OFF;
|
|
24
|
-
}
|
|
25
|
-
trace(...x) {
|
|
26
|
-
if (!this.enabledFor(this.TRACE))
|
|
27
|
-
return;
|
|
28
|
-
console.trace(...x);
|
|
29
|
-
const sanitized = this.sanitizeArgs(x);
|
|
30
|
-
this.iterateClients((client) => client.clientProvider.trace(...sanitized));
|
|
31
|
-
}
|
|
32
|
-
debug(...x) {
|
|
33
|
-
if (!this.enabledFor(this.DEBUG))
|
|
34
|
-
return;
|
|
35
|
-
console.debug(...x);
|
|
36
|
-
const sanitized = this.sanitizeArgs(x);
|
|
37
|
-
this.iterateClients((client) => client.clientProvider.debug(...sanitized));
|
|
38
|
-
}
|
|
39
|
-
info(...x) {
|
|
40
|
-
if (!this.enabledFor(this.INFO))
|
|
41
|
-
return;
|
|
42
|
-
console.info(...x);
|
|
43
|
-
const sanitized = this.sanitizeArgs(x);
|
|
44
|
-
this.iterateClients((client) => client.clientProvider.info(...sanitized));
|
|
45
|
-
}
|
|
46
|
-
log(...x) {
|
|
47
|
-
if (!this.enabledFor(this.INFO))
|
|
48
|
-
return;
|
|
49
|
-
console.log(...x);
|
|
50
|
-
const sanitized = this.sanitizeArgs(x);
|
|
51
|
-
this.iterateClients((client) => client.clientProvider.log(...sanitized));
|
|
52
|
-
}
|
|
53
|
-
warn(...x) {
|
|
54
|
-
if (!this.enabledFor(this.WARN))
|
|
55
|
-
return;
|
|
56
|
-
console.warn(...x);
|
|
57
|
-
const sanitized = this.sanitizeArgs(x);
|
|
58
|
-
this.iterateClients((client) => client.clientProvider.warn(...sanitized));
|
|
59
|
-
}
|
|
60
|
-
error(...x) {
|
|
61
|
-
if (!this.enabledFor(this.ERROR))
|
|
62
|
-
return;
|
|
63
|
-
console.error(...x);
|
|
64
|
-
const sanitized = this.sanitizeArgs(x);
|
|
65
|
-
this.iterateClients((client) => client.clientProvider.error(...sanitized));
|
|
66
|
-
}
|
|
67
|
-
time(label) {
|
|
68
|
-
if (!this.enabledFor(this.TIME))
|
|
69
|
-
return;
|
|
70
|
-
console.time(label);
|
|
71
|
-
this.iterateClients((client) => client.clientProvider.time(label));
|
|
72
|
-
}
|
|
73
|
-
timeEnd(label) {
|
|
74
|
-
if (!this.enabledFor(this.TIME))
|
|
75
|
-
return;
|
|
76
|
-
console.timeEnd(label);
|
|
77
|
-
this.iterateClients((client) => client.clientProvider.timeEnd(label));
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Set the global log level.
|
|
81
|
-
*/
|
|
82
|
-
setLevel(level) {
|
|
83
|
-
this.currentLevel = level;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Get the current log level.
|
|
87
|
-
*/
|
|
88
|
-
getLevel() {
|
|
89
|
-
return this.currentLevel;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Returns true if the given level is enabled.
|
|
93
|
-
*/
|
|
94
|
-
enabledFor(level) {
|
|
95
|
-
return level.value >= this.currentLevel.value;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Iterates all clients, catches individual client exceptions
|
|
99
|
-
* and proceeds to execute for all clients.
|
|
100
|
-
*/
|
|
101
|
-
async iterateClients(callback) {
|
|
102
|
-
for (const client of this.clients) {
|
|
103
|
-
try {
|
|
104
|
-
await callback(client);
|
|
105
|
-
}
|
|
106
|
-
catch (ex) {
|
|
107
|
-
console.error('Caught exception when iterating client', ex);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Guards against any logging errors.
|
|
113
|
-
* We don't want a logging exception to cause further issues upstream
|
|
114
|
-
*/
|
|
115
|
-
sanitizeArgs(x) {
|
|
116
|
-
const sanitizedParams = x.map((param) => {
|
|
117
|
-
try {
|
|
118
|
-
// Try and clone here first. If it fails it won't be passable over a MessagePort
|
|
119
|
-
return structuredClone(param);
|
|
120
|
-
}
|
|
121
|
-
catch (ex) {
|
|
122
|
-
console.error(ex);
|
|
123
|
-
return 'Could not serialize log params. Check shared worker logs for more details.';
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
return sanitizedParams;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|