@powersync/web 0.0.0-dev-20240723112746 → 0.0.0-dev-20240726145924
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/README.md +25 -1
- package/lib/src/db/PowerSyncDatabase.d.ts +2 -2
- package/lib/src/db/PowerSyncDatabase.js +28 -32
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js +1 -7
- package/lib/src/db/adapters/AbstractWebSQLOpenFactory.js +0 -2
- package/lib/src/db/adapters/SSRDBAdapter.js +48 -28
- package/lib/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.d.ts +1 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.js +136 -100
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +1 -4
- package/lib/src/db/adapters/web-sql-flags.js +3 -6
- package/lib/src/db/sync/SSRWebStreamingSyncImplementation.js +0 -2
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js +95 -66
- package/lib/src/db/sync/WebRemote.d.ts +1 -5
- package/lib/src/db/sync/WebRemote.js +21 -29
- package/lib/src/shared/open-db.js +184 -153
- package/lib/src/worker/db/SharedWASQLiteDB.worker.js +23 -15
- package/lib/src/worker/db/WASQLiteDB.worker.js +10 -1
- package/lib/src/worker/sync/BroadcastLogger.js +19 -16
- package/lib/src/worker/sync/SharedSyncImplementation.js +115 -96
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js +5 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -13
|
@@ -16,14 +16,11 @@ export const DEFAULT_WEB_SQL_FLAGS = {
|
|
|
16
16
|
useWebWorker: true
|
|
17
17
|
};
|
|
18
18
|
export function resolveWebSQLFlags(flags) {
|
|
19
|
-
const resolvedFlags = {
|
|
20
|
-
|
|
21
|
-
...(flags ?? {})
|
|
22
|
-
};
|
|
23
|
-
if (typeof flags?.enableMultiTabs != 'undefined') {
|
|
19
|
+
const resolvedFlags = Object.assign(Object.assign({}, DEFAULT_WEB_SQL_FLAGS), (flags !== null && flags !== void 0 ? flags : {}));
|
|
20
|
+
if (typeof (flags === null || flags === void 0 ? void 0 : flags.enableMultiTabs) != 'undefined') {
|
|
24
21
|
resolvedFlags.enableMultiTabs = flags.enableMultiTabs;
|
|
25
22
|
}
|
|
26
|
-
if (flags
|
|
23
|
+
if ((flags === null || flags === void 0 ? void 0 : flags.useWebWorker) === false) {
|
|
27
24
|
resolvedFlags.enableMultiTabs = false;
|
|
28
25
|
}
|
|
29
26
|
return resolvedFlags;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { AbstractStreamingSyncImplementation, LockType } from '@powersync/common';
|
|
2
2
|
import { Mutex } from 'async-mutex';
|
|
3
3
|
export class SSRStreamingSyncImplementation extends AbstractStreamingSyncImplementation {
|
|
4
|
-
syncMutex;
|
|
5
|
-
crudMutex;
|
|
6
4
|
constructor(options) {
|
|
7
5
|
super(options);
|
|
8
6
|
this.syncMutex = new Mutex();
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import * as Comlink from 'comlink';
|
|
2
11
|
import { WebStreamingSyncImplementation } from './WebStreamingSyncImplementation';
|
|
3
12
|
import { SharedSyncClientEvent } from '../../worker/sync/SharedSyncImplementation';
|
|
@@ -8,70 +17,76 @@ import { openWorkerDatabasePort } from '../../worker/db/open-worker-database';
|
|
|
8
17
|
* via this client provider.
|
|
9
18
|
*/
|
|
10
19
|
class SharedSyncClientProvider extends AbstractSharedSyncClientProvider {
|
|
11
|
-
options;
|
|
12
|
-
statusChanged;
|
|
13
20
|
constructor(options, statusChanged) {
|
|
14
21
|
super();
|
|
15
22
|
this.options = options;
|
|
16
23
|
this.statusChanged = statusChanged;
|
|
17
24
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
fetchCredentials() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const credentials = yield this.options.remote.getCredentials();
|
|
28
|
+
if (credentials == null) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The credentials need to be serializable.
|
|
33
|
+
* Users might extend [PowerSyncCredentials] to contain
|
|
34
|
+
* items which are not serializable.
|
|
35
|
+
* This returns only the essential fields.
|
|
36
|
+
*/
|
|
37
|
+
return {
|
|
38
|
+
endpoint: credentials.endpoint,
|
|
39
|
+
token: credentials.token,
|
|
40
|
+
expiresAt: credentials.expiresAt
|
|
41
|
+
};
|
|
42
|
+
});
|
|
34
43
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
uploadCrud() {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
/**
|
|
47
|
+
* Don't return anything here, just incase something which is not
|
|
48
|
+
* serializable is returned from the `uploadCrud` function.
|
|
49
|
+
*/
|
|
50
|
+
yield this.options.uploadCrud();
|
|
51
|
+
});
|
|
41
52
|
}
|
|
42
53
|
get logger() {
|
|
43
54
|
return this.options.logger;
|
|
44
55
|
}
|
|
45
56
|
trace(...x) {
|
|
46
|
-
|
|
57
|
+
var _a;
|
|
58
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(...x);
|
|
47
59
|
}
|
|
48
60
|
debug(...x) {
|
|
49
|
-
|
|
61
|
+
var _a;
|
|
62
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(...x);
|
|
50
63
|
}
|
|
51
64
|
info(...x) {
|
|
52
|
-
|
|
65
|
+
var _a;
|
|
66
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(...x);
|
|
53
67
|
}
|
|
54
68
|
log(...x) {
|
|
55
|
-
|
|
69
|
+
var _a;
|
|
70
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(...x);
|
|
56
71
|
}
|
|
57
72
|
warn(...x) {
|
|
58
|
-
|
|
73
|
+
var _a;
|
|
74
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn(...x);
|
|
59
75
|
}
|
|
60
76
|
error(...x) {
|
|
61
|
-
|
|
77
|
+
var _a;
|
|
78
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(...x);
|
|
62
79
|
}
|
|
63
80
|
time(label) {
|
|
64
|
-
|
|
81
|
+
var _a;
|
|
82
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.time(label);
|
|
65
83
|
}
|
|
66
84
|
timeEnd(label) {
|
|
67
|
-
|
|
85
|
+
var _a;
|
|
86
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.timeEnd(label);
|
|
68
87
|
}
|
|
69
88
|
}
|
|
70
89
|
export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplementation {
|
|
71
|
-
syncManager;
|
|
72
|
-
clientProvider;
|
|
73
|
-
messagePort;
|
|
74
|
-
isInitialized;
|
|
75
90
|
constructor(options) {
|
|
76
91
|
super(options);
|
|
77
92
|
/**
|
|
@@ -120,39 +135,53 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
120
135
|
* Starts the sync process, this effectively acts as a call to
|
|
121
136
|
* `connect` if not yet connected.
|
|
122
137
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return this
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
this
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
138
|
+
connect(options) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
yield this.waitForReady();
|
|
141
|
+
return this.syncManager.connect(options);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
disconnect() {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
yield this.waitForReady();
|
|
147
|
+
return this.syncManager.disconnect();
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
getWriteCheckpoint() {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
yield this.waitForReady();
|
|
153
|
+
return this.syncManager.getWriteCheckpoint();
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
hasCompletedSync() {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
return this.syncManager.hasCompletedSync();
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
dispose() {
|
|
162
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
yield this.waitForReady();
|
|
164
|
+
// Signal the shared worker that this client is closing its connection to the worker
|
|
165
|
+
const closeMessagePayload = {
|
|
166
|
+
event: SharedSyncClientEvent.CLOSE_CLIENT,
|
|
167
|
+
data: {}
|
|
168
|
+
};
|
|
169
|
+
this.messagePort.postMessage(closeMessagePayload);
|
|
170
|
+
// Release the proxy
|
|
171
|
+
this.syncManager[Comlink.releaseProxy]();
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
waitForReady() {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
return this.isInitialized;
|
|
177
|
+
});
|
|
151
178
|
}
|
|
152
179
|
/**
|
|
153
180
|
* Used in tests to force a connection states
|
|
154
181
|
*/
|
|
155
|
-
|
|
156
|
-
return this
|
|
182
|
+
_testUpdateStatus(status) {
|
|
183
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
+
return this.syncManager['_testUpdateAllStatuses'](status.toJSON());
|
|
185
|
+
});
|
|
157
186
|
}
|
|
158
187
|
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbstractRemote, AbstractRemoteOptions, BSONImplementation, RemoteConnector } from '@powersync/common';
|
|
1
|
+
import { AbstractRemote, BSONImplementation } from '@powersync/common';
|
|
3
2
|
export declare class WebRemote extends AbstractRemote {
|
|
4
|
-
protected connector: RemoteConnector;
|
|
5
|
-
protected logger: ILogger;
|
|
6
3
|
private _bson;
|
|
7
|
-
constructor(connector: RemoteConnector, logger?: ILogger, options?: Partial<AbstractRemoteOptions>);
|
|
8
4
|
getBSON(): Promise<BSONImplementation>;
|
|
9
5
|
}
|
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
}
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { AbstractRemote } from '@powersync/common';
|
|
10
11
|
export class WebRemote extends AbstractRemote {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
async getBSON() {
|
|
23
|
-
if (this._bson) {
|
|
12
|
+
getBSON() {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
if (this._bson) {
|
|
15
|
+
return this._bson;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Dynamic import to be used only when needed.
|
|
19
|
+
*/
|
|
20
|
+
const { BSON } = yield import('bson');
|
|
21
|
+
this._bson = BSON;
|
|
24
22
|
return this._bson;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Dynamic import to be used only when needed.
|
|
28
|
-
*/
|
|
29
|
-
const { BSON } = await import('bson');
|
|
30
|
-
this._bson = BSON;
|
|
31
|
-
return this._bson;
|
|
23
|
+
});
|
|
32
24
|
}
|
|
33
25
|
}
|