@powersync/web 1.17.2 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/powersync.js +3 -1
- package/dist/{_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js-_powersync_co-780aa20.index.umd.js → _journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapp-81d3460.index.umd.js} +27 -7
- package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapp-81d3460.index.umd.js.map +1 -0
- package/dist/{_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js-_powersync_co-780aa21.index.umd.js → _journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapp-81d3461.index.umd.js} +27 -7
- package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapp-81d3461.index.umd.js.map +1 -0
- package/dist/index.umd.js +105 -2701
- package/dist/index.umd.js.map +1 -1
- package/dist/worker/SharedSyncImplementation.umd.js +148 -424
- package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
- package/dist/worker/WASQLiteDB.umd.js +101 -378
- package/dist/worker/WASQLiteDB.umd.js.map +1 -1
- package/lib/package.json +3 -4
- package/lib/src/db/adapters/AbstractWebSQLOpenFactory.d.ts +1 -2
- package/lib/src/db/adapters/AbstractWebSQLOpenFactory.js +4 -4
- package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.d.ts +1 -2
- package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.js +2 -3
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +4 -1
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +2 -1
- package/lib/src/db/adapters/web-sql-flags.d.ts +1 -2
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js +1 -0
- package/lib/src/db/sync/WebRemote.d.ts +1 -2
- package/lib/src/db/sync/WebStreamingSyncImplementation.js +3 -1
- package/lib/src/worker/db/WASQLiteDB.worker.js +9 -5
- package/lib/src/worker/sync/BroadcastLogger.d.ts +11 -1
- package/lib/src/worker/sync/BroadcastLogger.js +37 -13
- package/lib/src/worker/sync/SharedSyncImplementation.d.ts +2 -2
- package/lib/src/worker/sync/SharedSyncImplementation.js +8 -5
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js +3 -3
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js-_powersync_co-780aa20.index.umd.js.map +0 -1
- package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js-_powersync_co-780aa21.index.umd.js.map +0 -1
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"description": "PowerSync web SDK. Sync Postgres, MongoDB or MySQL with SQLite in your web app",
|
|
5
5
|
"main": "lib/src/index.js",
|
|
6
6
|
"types": "lib/src/index.d.ts",
|
|
@@ -61,15 +61,14 @@
|
|
|
61
61
|
"license": "Apache-2.0",
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"@journeyapps/wa-sqlite": "^1.2.2",
|
|
64
|
-
"@powersync/common": "workspace:^1.
|
|
64
|
+
"@powersync/common": "workspace:^1.28.0"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@powersync/common": "workspace:*",
|
|
68
68
|
"async-mutex": "^0.4.0",
|
|
69
69
|
"bson": "^6.6.0",
|
|
70
70
|
"comlink": "^4.4.2",
|
|
71
|
-
"commander": "^12.1.0"
|
|
72
|
-
"js-logger": "^1.6.1"
|
|
71
|
+
"commander": "^12.1.0"
|
|
73
72
|
},
|
|
74
73
|
"devDependencies": {
|
|
75
74
|
"@journeyapps/wa-sqlite": "^1.2.2",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { DBAdapter, SQLOpenFactory } from '@powersync/common';
|
|
2
|
-
import { ILogger } from 'js-logger';
|
|
1
|
+
import { type ILogger, DBAdapter, SQLOpenFactory } from '@powersync/common';
|
|
3
2
|
import { ResolvedWebSQLFlags, WebSQLOpenFactoryOptions } from './web-sql-flags';
|
|
4
3
|
export declare abstract class AbstractWebSQLOpenFactory implements SQLOpenFactory {
|
|
5
4
|
protected options: WebSQLOpenFactoryOptions;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createLogger } from '@powersync/common';
|
|
2
2
|
import { SSRDBAdapter } from './SSRDBAdapter';
|
|
3
3
|
import { isServerSide, resolveWebSQLFlags } from './web-sql-flags';
|
|
4
4
|
export class AbstractWebSQLOpenFactory {
|
|
@@ -8,7 +8,7 @@ export class AbstractWebSQLOpenFactory {
|
|
|
8
8
|
constructor(options) {
|
|
9
9
|
this.options = options;
|
|
10
10
|
this.resolvedFlags = resolveWebSQLFlags(options.flags);
|
|
11
|
-
this.logger = options.logger ??
|
|
11
|
+
this.logger = options.logger ?? createLogger(`AbstractWebSQLOpenFactory - ${this.options.dbFilename}`);
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Opens a {@link DBAdapter} using resolved flags.
|
|
@@ -17,13 +17,13 @@ export class AbstractWebSQLOpenFactory {
|
|
|
17
17
|
openDB() {
|
|
18
18
|
const { resolvedFlags: { disableSSRWarning, enableMultiTabs, ssrMode = isServerSide() } } = this;
|
|
19
19
|
if (ssrMode && !disableSSRWarning) {
|
|
20
|
-
|
|
20
|
+
this.logger.warn(`
|
|
21
21
|
Running PowerSync in SSR mode.
|
|
22
22
|
Only empty query results will be returned.
|
|
23
23
|
Disable this warning by setting 'disableSSRWarning: true' in options.`);
|
|
24
24
|
}
|
|
25
25
|
if (!enableMultiTabs) {
|
|
26
|
-
|
|
26
|
+
this.logger.warn('Multiple tab support is not enabled. Using this site across multiple tabs may not function correctly.');
|
|
27
27
|
}
|
|
28
28
|
if (ssrMode) {
|
|
29
29
|
return new SSRDBAdapter();
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { BaseObserver, DBAdapterListener, DBLockOptions, LockContext, QueryResult, Transaction } from '@powersync/common';
|
|
2
|
-
import { ILogger } from 'js-logger';
|
|
1
|
+
import { type ILogger, BaseObserver, DBAdapterListener, DBLockOptions, LockContext, QueryResult, Transaction } from '@powersync/common';
|
|
3
2
|
import { AsyncDatabaseConnection } from './AsyncDatabaseConnection';
|
|
4
3
|
import { SharedConnectionWorker, WebDBAdapter } from './WebDBAdapter';
|
|
5
4
|
import { ResolvedWebSQLOpenOptions } from './web-sql-flags';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { BaseObserver } from '@powersync/common';
|
|
2
|
-
import Logger from 'js-logger';
|
|
1
|
+
import { BaseObserver, createLogger } from '@powersync/common';
|
|
3
2
|
import { getNavigatorLocks } from '../..//shared/navigator';
|
|
4
3
|
import { WorkerWrappedAsyncDatabaseConnection } from './WorkerWrappedAsyncDatabaseConnection';
|
|
5
4
|
/**
|
|
@@ -21,7 +20,7 @@ export class LockedAsyncDatabaseAdapter extends BaseObserver {
|
|
|
21
20
|
super();
|
|
22
21
|
this.options = options;
|
|
23
22
|
this._dbIdentifier = options.name;
|
|
24
|
-
this.logger = options.logger ??
|
|
23
|
+
this.logger = options.logger ?? createLogger(`LockedAsyncDatabaseAdapter - ${this._dbIdentifier}`);
|
|
25
24
|
// Set the name if provided. We can query for the name if not available yet
|
|
26
25
|
this.debugMode = options.debugMode ?? false;
|
|
27
26
|
if (this.debugMode) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DBAdapter } from '@powersync/common';
|
|
1
|
+
import { type ILogLevel, DBAdapter } from '@powersync/common';
|
|
2
2
|
import { AbstractWebSQLOpenFactory } from '../AbstractWebSQLOpenFactory';
|
|
3
3
|
import { AsyncDatabaseConnection } from '../AsyncDatabaseConnection';
|
|
4
4
|
import { ResolvedWebSQLOpenOptions, WebSQLOpenFactoryOptions } from '../web-sql-flags';
|
|
@@ -9,6 +9,9 @@ export interface WASQLiteOpenFactoryOptions extends WebSQLOpenFactoryOptions {
|
|
|
9
9
|
export interface ResolvedWASQLiteOpenFactoryOptions extends ResolvedWebSQLOpenOptions {
|
|
10
10
|
vfs: WASQLiteVFS;
|
|
11
11
|
}
|
|
12
|
+
export interface WorkerDBOpenerOptions extends ResolvedWASQLiteOpenFactoryOptions {
|
|
13
|
+
logLevel: ILogLevel;
|
|
14
|
+
}
|
|
12
15
|
/**
|
|
13
16
|
* Opens a SQLite connection using WA-SQLite.
|
|
14
17
|
*/
|
|
@@ -51,7 +51,8 @@ export class WASQLiteOpenFactory extends AbstractWebSQLOpenFactory {
|
|
|
51
51
|
temporaryStorage,
|
|
52
52
|
cacheSizeKb,
|
|
53
53
|
flags: this.resolvedFlags,
|
|
54
|
-
encryptionKey: encryptionKey
|
|
54
|
+
encryptionKey: encryptionKey,
|
|
55
|
+
logLevel: this.logger.getLevel()
|
|
55
56
|
}),
|
|
56
57
|
identifier: this.options.dbFilename,
|
|
57
58
|
onClose: () => {
|
|
@@ -112,6 +112,7 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
112
112
|
}).port;
|
|
113
113
|
}
|
|
114
114
|
this.syncManager = Comlink.wrap(this.messagePort);
|
|
115
|
+
this.syncManager.setLogLevel(this.logger.getLevel());
|
|
115
116
|
this.triggerCrudUpload = this.syncManager.triggerCrudUpload;
|
|
116
117
|
/**
|
|
117
118
|
* Opens MessagePort to the existing shared DB worker.
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbstractRemote, AbstractRemoteOptions, BSONImplementation, RemoteConnector } from '@powersync/common';
|
|
1
|
+
import { AbstractRemote, AbstractRemoteOptions, BSONImplementation, ILogger, RemoteConnector } from '@powersync/common';
|
|
3
2
|
export declare class WebRemote extends AbstractRemote {
|
|
4
3
|
protected connector: RemoteConnector;
|
|
5
4
|
protected logger: ILogger;
|
|
@@ -10,7 +10,9 @@ export class WebStreamingSyncImplementation extends AbstractStreamingSyncImpleme
|
|
|
10
10
|
}
|
|
11
11
|
obtainLock(lockOptions) {
|
|
12
12
|
const identifier = `streaming-sync-${lockOptions.type}-${this.webOptions.identifier}`;
|
|
13
|
-
lockOptions.type == LockType.SYNC
|
|
13
|
+
if (lockOptions.type == LockType.SYNC) {
|
|
14
|
+
this.logger.debug('requesting lock for ', identifier);
|
|
15
|
+
}
|
|
14
16
|
return getNavigatorLocks().request(identifier, { signal: lockOptions.signal }, lockOptions.callback);
|
|
15
17
|
}
|
|
16
18
|
}
|
|
@@ -5,6 +5,10 @@ import '@journeyapps/wa-sqlite';
|
|
|
5
5
|
import * as Comlink from 'comlink';
|
|
6
6
|
import { WASqliteConnection } from '../../db/adapters/wa-sqlite/WASQLiteConnection';
|
|
7
7
|
import { getNavigatorLocks } from '../../shared/navigator';
|
|
8
|
+
import { createBaseLogger, createLogger } from '@powersync/common';
|
|
9
|
+
const baseLogger = createBaseLogger();
|
|
10
|
+
baseLogger.useDefaults();
|
|
11
|
+
const logger = createLogger('db-worker');
|
|
8
12
|
const DBMap = new Map();
|
|
9
13
|
const OPEN_DB_LOCK = 'open-wasqlite-db';
|
|
10
14
|
let nextClientId = 1;
|
|
@@ -27,7 +31,8 @@ const openDBShared = async (options) => {
|
|
|
27
31
|
// Prevent multiple simultaneous opens from causing race conditions
|
|
28
32
|
return getNavigatorLocks().request(OPEN_DB_LOCK, async () => {
|
|
29
33
|
const clientId = nextClientId++;
|
|
30
|
-
const { dbFilename } = options;
|
|
34
|
+
const { dbFilename, logLevel } = options;
|
|
35
|
+
logger.setLevel(logLevel);
|
|
31
36
|
if (!DBMap.has(dbFilename)) {
|
|
32
37
|
const clientIds = new Set();
|
|
33
38
|
const connection = await openWorkerConnection(options);
|
|
@@ -47,14 +52,14 @@ const openDBShared = async (options) => {
|
|
|
47
52
|
}),
|
|
48
53
|
close: Comlink.proxy(() => {
|
|
49
54
|
const { clientIds } = dbEntry;
|
|
50
|
-
|
|
55
|
+
logger.debug(`Close requested from client ${clientId} of ${[...clientIds]}`);
|
|
51
56
|
clientIds.delete(clientId);
|
|
52
57
|
if (clientIds.size == 0) {
|
|
53
|
-
|
|
58
|
+
logger.debug(`Closing connection to ${dbFilename}.`);
|
|
54
59
|
DBMap.delete(dbFilename);
|
|
55
60
|
return db.close?.();
|
|
56
61
|
}
|
|
57
|
-
|
|
62
|
+
logger.debug(`Connection to ${dbFilename} not closed yet due to active clients.`);
|
|
58
63
|
return;
|
|
59
64
|
})
|
|
60
65
|
};
|
|
@@ -66,7 +71,6 @@ if (typeof SharedWorkerGlobalScope !== 'undefined') {
|
|
|
66
71
|
const _self = self;
|
|
67
72
|
_self.onconnect = function (event) {
|
|
68
73
|
const port = event.ports[0];
|
|
69
|
-
console.debug('Exposing shared db on port', port);
|
|
70
74
|
Comlink.expose(openDBShared, port);
|
|
71
75
|
};
|
|
72
76
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ILogger, type ILogLevel } from '@powersync/common';
|
|
2
2
|
import { type WrappedSyncPort } from './SharedSyncImplementation';
|
|
3
3
|
/**
|
|
4
4
|
* Broadcasts logs to all clients
|
|
@@ -12,6 +12,7 @@ export declare class BroadcastLogger implements ILogger {
|
|
|
12
12
|
WARN: ILogLevel;
|
|
13
13
|
ERROR: ILogLevel;
|
|
14
14
|
OFF: ILogLevel;
|
|
15
|
+
private currentLevel;
|
|
15
16
|
constructor(clients: WrappedSyncPort[]);
|
|
16
17
|
trace(...x: any[]): void;
|
|
17
18
|
debug(...x: any[]): void;
|
|
@@ -21,8 +22,17 @@ export declare class BroadcastLogger implements ILogger {
|
|
|
21
22
|
error(...x: any[]): void;
|
|
22
23
|
time(label: string): void;
|
|
23
24
|
timeEnd(label: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Set the global log level.
|
|
27
|
+
*/
|
|
24
28
|
setLevel(level: ILogLevel): void;
|
|
29
|
+
/**
|
|
30
|
+
* Get the current log level.
|
|
31
|
+
*/
|
|
25
32
|
getLevel(): ILogLevel;
|
|
33
|
+
/**
|
|
34
|
+
* Returns true if the given level is enabled.
|
|
35
|
+
*/
|
|
26
36
|
enabledFor(level: ILogLevel): boolean;
|
|
27
37
|
/**
|
|
28
38
|
* Iterates all clients, catches individual client exceptions
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { LogLevel } from '@powersync/common';
|
|
2
2
|
/**
|
|
3
3
|
* Broadcasts logs to all clients
|
|
4
4
|
*/
|
|
@@ -11,64 +11,88 @@ export class BroadcastLogger {
|
|
|
11
11
|
WARN;
|
|
12
12
|
ERROR;
|
|
13
13
|
OFF;
|
|
14
|
+
currentLevel = LogLevel.INFO;
|
|
14
15
|
constructor(clients) {
|
|
15
16
|
this.clients = clients;
|
|
16
|
-
this.TRACE =
|
|
17
|
-
this.DEBUG =
|
|
18
|
-
this.INFO =
|
|
19
|
-
this.TIME =
|
|
20
|
-
this.WARN =
|
|
21
|
-
this.ERROR =
|
|
22
|
-
this.OFF =
|
|
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;
|
|
23
24
|
}
|
|
24
25
|
trace(...x) {
|
|
26
|
+
if (!this.enabledFor(this.TRACE))
|
|
27
|
+
return;
|
|
25
28
|
console.trace(...x);
|
|
26
29
|
const sanitized = this.sanitizeArgs(x);
|
|
27
30
|
this.iterateClients((client) => client.clientProvider.trace(...sanitized));
|
|
28
31
|
}
|
|
29
32
|
debug(...x) {
|
|
33
|
+
if (!this.enabledFor(this.DEBUG))
|
|
34
|
+
return;
|
|
30
35
|
console.debug(...x);
|
|
31
36
|
const sanitized = this.sanitizeArgs(x);
|
|
32
37
|
this.iterateClients((client) => client.clientProvider.debug(...sanitized));
|
|
33
38
|
}
|
|
34
39
|
info(...x) {
|
|
40
|
+
if (!this.enabledFor(this.INFO))
|
|
41
|
+
return;
|
|
35
42
|
console.info(...x);
|
|
36
43
|
const sanitized = this.sanitizeArgs(x);
|
|
37
44
|
this.iterateClients((client) => client.clientProvider.info(...sanitized));
|
|
38
45
|
}
|
|
39
46
|
log(...x) {
|
|
47
|
+
if (!this.enabledFor(this.INFO))
|
|
48
|
+
return;
|
|
40
49
|
console.log(...x);
|
|
41
50
|
const sanitized = this.sanitizeArgs(x);
|
|
42
51
|
this.iterateClients((client) => client.clientProvider.log(...sanitized));
|
|
43
52
|
}
|
|
44
53
|
warn(...x) {
|
|
54
|
+
if (!this.enabledFor(this.WARN))
|
|
55
|
+
return;
|
|
45
56
|
console.warn(...x);
|
|
46
57
|
const sanitized = this.sanitizeArgs(x);
|
|
47
58
|
this.iterateClients((client) => client.clientProvider.warn(...sanitized));
|
|
48
59
|
}
|
|
49
60
|
error(...x) {
|
|
61
|
+
if (!this.enabledFor(this.ERROR))
|
|
62
|
+
return;
|
|
50
63
|
console.error(...x);
|
|
51
64
|
const sanitized = this.sanitizeArgs(x);
|
|
52
65
|
this.iterateClients((client) => client.clientProvider.error(...sanitized));
|
|
53
66
|
}
|
|
54
67
|
time(label) {
|
|
68
|
+
if (!this.enabledFor(this.TIME))
|
|
69
|
+
return;
|
|
55
70
|
console.time(label);
|
|
56
71
|
this.iterateClients((client) => client.clientProvider.time(label));
|
|
57
72
|
}
|
|
58
73
|
timeEnd(label) {
|
|
74
|
+
if (!this.enabledFor(this.TIME))
|
|
75
|
+
return;
|
|
59
76
|
console.timeEnd(label);
|
|
60
77
|
this.iterateClients((client) => client.clientProvider.timeEnd(label));
|
|
61
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Set the global log level.
|
|
81
|
+
*/
|
|
62
82
|
setLevel(level) {
|
|
63
|
-
|
|
83
|
+
this.currentLevel = level;
|
|
64
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Get the current log level.
|
|
87
|
+
*/
|
|
65
88
|
getLevel() {
|
|
66
|
-
|
|
67
|
-
return Logger.INFO;
|
|
89
|
+
return this.currentLevel;
|
|
68
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns true if the given level is enabled.
|
|
93
|
+
*/
|
|
69
94
|
enabledFor(level) {
|
|
70
|
-
|
|
71
|
-
return true;
|
|
95
|
+
return level.value >= this.currentLevel.value;
|
|
72
96
|
}
|
|
73
97
|
/**
|
|
74
98
|
* Iterates all clients, catches individual client exceptions
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { type AbstractStreamingSyncImplementation, type LockOptions, type PowerSyncConnectionOptions, type StreamingSyncImplementation, type StreamingSyncImplementationListener, type SyncStatusOptions, BaseObserver, DBAdapter, SyncStatus } from '@powersync/common';
|
|
1
|
+
import { type AbstractStreamingSyncImplementation, type ILogger, type ILogLevel, type LockOptions, type PowerSyncConnectionOptions, type StreamingSyncImplementation, type StreamingSyncImplementationListener, type SyncStatusOptions, BaseObserver, DBAdapter, SyncStatus } from '@powersync/common';
|
|
2
2
|
import * as Comlink from 'comlink';
|
|
3
|
-
import { type ILogger } from 'js-logger';
|
|
4
3
|
import { WebStreamingSyncImplementation, WebStreamingSyncImplementationOptions } from '../../db/sync/WebStreamingSyncImplementation';
|
|
5
4
|
import { ResolvedWebSQLOpenOptions } from '../../db/adapters/web-sql-flags';
|
|
6
5
|
import { AbstractSharedSyncClientProvider } from './AbstractSharedSyncClientProvider';
|
|
@@ -69,6 +68,7 @@ export declare class SharedSyncImplementation extends BaseObserver<SharedSyncImp
|
|
|
69
68
|
get lastSyncedAt(): Date | undefined;
|
|
70
69
|
get isConnected(): boolean;
|
|
71
70
|
waitForReady(): Promise<void>;
|
|
71
|
+
setLogLevel(level: ILogLevel): void;
|
|
72
72
|
/**
|
|
73
73
|
* Configures the DBAdapter connection and a streaming sync client.
|
|
74
74
|
*/
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { AbortOperation, BaseObserver, SqliteBucketStorage, SyncStatus } from '@powersync/common';
|
|
1
|
+
import { AbortOperation, BaseObserver, createLogger, SqliteBucketStorage, SyncStatus } from '@powersync/common';
|
|
2
2
|
import { Mutex } from 'async-mutex';
|
|
3
3
|
import * as Comlink from 'comlink';
|
|
4
|
-
import Logger from 'js-logger';
|
|
5
4
|
import { WebRemote } from '../../db/sync/WebRemote';
|
|
6
5
|
import { WebStreamingSyncImplementation } from '../../db/sync/WebStreamingSyncImplementation';
|
|
7
6
|
import { LockedAsyncDatabaseAdapter } from '../../db/adapters/LockedAsyncDatabaseAdapter';
|
|
@@ -42,7 +41,7 @@ export class SharedSyncImplementation extends BaseObserver {
|
|
|
42
41
|
this.dbAdapter = null;
|
|
43
42
|
this.syncParams = null;
|
|
44
43
|
this.syncStreamClient = null;
|
|
45
|
-
this.logger =
|
|
44
|
+
this.logger = createLogger('shared-sync');
|
|
46
45
|
this.lastConnectOptions = undefined;
|
|
47
46
|
this.isInitialized = new Promise((resolve) => {
|
|
48
47
|
const callback = this.registerListener({
|
|
@@ -72,6 +71,10 @@ export class SharedSyncImplementation extends BaseObserver {
|
|
|
72
71
|
async waitForReady() {
|
|
73
72
|
return this.isInitialized;
|
|
74
73
|
}
|
|
74
|
+
setLogLevel(level) {
|
|
75
|
+
this.logger.setLevel(level);
|
|
76
|
+
this.broadCastLogger.setLevel(level);
|
|
77
|
+
}
|
|
75
78
|
/**
|
|
76
79
|
* Configures the DBAdapter connection and a streaming sync client.
|
|
77
80
|
*/
|
|
@@ -150,7 +153,7 @@ export class SharedSyncImplementation extends BaseObserver {
|
|
|
150
153
|
async removePort(port) {
|
|
151
154
|
const index = this.ports.findIndex((p) => p.port == port);
|
|
152
155
|
if (index < 0) {
|
|
153
|
-
|
|
156
|
+
this.logger.warn(`Could not remove port ${port} since it is not present in active ports.`);
|
|
154
157
|
return;
|
|
155
158
|
}
|
|
156
159
|
const trackedPort = this.ports[index];
|
|
@@ -214,7 +217,7 @@ export class SharedSyncImplementation extends BaseObserver {
|
|
|
214
217
|
};
|
|
215
218
|
abortController.signal.onabort = reject;
|
|
216
219
|
try {
|
|
217
|
-
|
|
220
|
+
this.logger.log('calling the last port client provider for credentials');
|
|
218
221
|
resolve(await lastPort.clientProvider.fetchCredentials());
|
|
219
222
|
}
|
|
220
223
|
catch (ex) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as Comlink from 'comlink';
|
|
2
2
|
import { SharedSyncImplementation, SharedSyncClientEvent } from './SharedSyncImplementation';
|
|
3
|
-
import
|
|
3
|
+
import { createBaseLogger } from '@powersync/common';
|
|
4
4
|
const _self = self;
|
|
5
|
-
|
|
5
|
+
const logger = createBaseLogger();
|
|
6
|
+
logger.useDefaults();
|
|
6
7
|
const sharedSyncImplementation = new SharedSyncImplementation();
|
|
7
8
|
_self.onconnect = function (event) {
|
|
8
9
|
const port = event.ports[0];
|
|
@@ -13,7 +14,6 @@ _self.onconnect = function (event) {
|
|
|
13
14
|
port.addEventListener('message', (event) => {
|
|
14
15
|
const payload = event.data;
|
|
15
16
|
if (payload?.event == SharedSyncClientEvent.CLOSE_CLIENT) {
|
|
16
|
-
console.log('closing shared for port', port);
|
|
17
17
|
sharedSyncImplementation.removePort(port);
|
|
18
18
|
}
|
|
19
19
|
});
|