@powersync/web 0.5.3 → 0.6.1
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 +24 -0
- package/lib/src/db/PowerSyncDatabase.d.ts +2 -2
- package/lib/src/db/PowerSyncDatabase.js +2 -3
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js +0 -1
- package/lib/src/db/adapters/SSRDBAdapter.js +0 -1
- package/lib/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.js +0 -1
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js +0 -1
- package/lib/src/db/sync/SSRWebStreamingSyncImplementation.js +0 -1
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.d.ts +2 -2
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js +2 -3
- package/lib/src/db/sync/WebRemote.d.ts +0 -3
- package/lib/src/db/sync/WebRemote.js +1 -132
- package/lib/src/db/sync/WebStreamingSyncImplementation.js +0 -1
- package/lib/src/index.js +0 -1
- package/lib/src/worker/db/SharedWASQLiteDB.worker.js +2 -3
- package/lib/src/worker/db/WASQLiteDB.worker.js +0 -1
- package/lib/src/worker/db/open-db.js +2 -3
- package/lib/src/worker/db/open-worker-database.js +0 -1
- package/lib/src/worker/sync/AbstractSharedSyncClientProvider.js +0 -1
- package/lib/src/worker/sync/BroadcastLogger.js +0 -1
- package/lib/src/worker/sync/SharedSyncImplementation.d.ts +2 -2
- package/lib/src/worker/sync/SharedSyncImplementation.js +2 -3
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js +4 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -5
- package/lib/src/db/PowerSyncDatabase.js.map +0 -1
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js.map +0 -1
- package/lib/src/db/adapters/SSRDBAdapter.js.map +0 -1
- package/lib/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.js.map +0 -1
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js.map +0 -1
- package/lib/src/db/sync/SSRWebStreamingSyncImplementation.js.map +0 -1
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js.map +0 -1
- package/lib/src/db/sync/WebRemote.js.map +0 -1
- package/lib/src/db/sync/WebStreamingSyncImplementation.js.map +0 -1
- package/lib/src/index.js.map +0 -1
- package/lib/src/worker/db/SharedWASQLiteDB.worker.js.map +0 -1
- package/lib/src/worker/db/WASQLiteDB.worker.js.map +0 -1
- package/lib/src/worker/db/open-db.js.map +0 -1
- package/lib/src/worker/db/open-worker-database.js.map +0 -1
- package/lib/src/worker/sync/AbstractSharedSyncClientProvider.js.map +0 -1
- package/lib/src/worker/sync/BroadcastLogger.js.map +0 -1
- package/lib/src/worker/sync/SharedSyncImplementation.js.map +0 -1
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js.map +0 -1
package/README.md
CHANGED
|
@@ -32,6 +32,30 @@ Install it in your app with:
|
|
|
32
32
|
npm install @journeyapps/wa-sqlite
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
## Polyfills
|
|
36
|
+
|
|
37
|
+
### WebSocket Connections: Buffer
|
|
38
|
+
|
|
39
|
+
Note: Beta Release - WebSockets are currently in a beta release. It should be safe to use in production if sufficient testing is done on the client side.
|
|
40
|
+
|
|
41
|
+
This SDK connects to a PowerSync instance via HTTP streams (enabled by default) or WebSockets. The WebSocket connection method requires `Buffer` to be available in the global scope. When multiple tabs are used the shared web worker will apply a polyfill in its own scope, but the `Buffer` class should be polyfills in the application for cases where multiple tabs are not supported.
|
|
42
|
+
|
|
43
|
+
Install a suitable Buffer implementation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm install buffer
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Apply it in your application if not yet provided
|
|
50
|
+
|
|
51
|
+
```Javascript
|
|
52
|
+
import { Buffer } from 'buffer';
|
|
53
|
+
|
|
54
|
+
if (typeof self.Buffer == 'undefined') {
|
|
55
|
+
self.Buffer = Buffer;
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
35
59
|
# Getting Started
|
|
36
60
|
|
|
37
61
|
Our [full SDK reference](https://docs.powersync.com/client-sdk-references/js-web) contains everything you need to know to get started implementing PowerSync in your project.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractPowerSyncDatabase, AbstractStreamingSyncImplementation, PowerSyncBackendConnector, BucketStorageAdapter, PowerSyncDatabaseOptions, PowerSyncCloseOptions } from '@powersync/common';
|
|
1
|
+
import { AbstractPowerSyncDatabase, AbstractStreamingSyncImplementation, PowerSyncBackendConnector, BucketStorageAdapter, PowerSyncDatabaseOptions, PowerSyncCloseOptions, PowerSyncConnectionOptions } from '@powersync/common';
|
|
2
2
|
import { Mutex } from 'async-mutex';
|
|
3
3
|
export interface WebPowerSyncFlags {
|
|
4
4
|
/**
|
|
@@ -36,7 +36,7 @@ export declare class PowerSyncDatabase extends AbstractPowerSyncDatabase {
|
|
|
36
36
|
* multiple tabs are not enabled.
|
|
37
37
|
*/
|
|
38
38
|
close(options?: PowerSyncCloseOptions): Promise<void>;
|
|
39
|
-
connect(connector: PowerSyncBackendConnector): Promise<void>;
|
|
39
|
+
connect(connector: PowerSyncBackendConnector, options?: PowerSyncConnectionOptions): Promise<void>;
|
|
40
40
|
protected generateBucketStorageAdapter(): BucketStorageAdapter;
|
|
41
41
|
protected runExclusive<T>(cb: () => Promise<T>): Promise<any>;
|
|
42
42
|
protected generateSyncStreamImplementation(connector: PowerSyncBackendConnector): AbstractStreamingSyncImplementation;
|
|
@@ -41,7 +41,7 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
|
|
|
41
41
|
disconnect: (_a = options.disconnect) !== null && _a !== void 0 ? _a : !((_b = this.options.flags) === null || _b === void 0 ? void 0 : _b.enableMultiTabs)
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
-
connect(connector) {
|
|
44
|
+
connect(connector, options) {
|
|
45
45
|
/**
|
|
46
46
|
* Using React strict mode might cause calls to connect to fire multiple times
|
|
47
47
|
* Connect is wrapped inside a lock in order to prevent race conditions internally between multiple
|
|
@@ -50,7 +50,7 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
|
|
|
50
50
|
return this.runExclusive(() => {
|
|
51
51
|
var _a;
|
|
52
52
|
(_a = this.options.logger) === null || _a === void 0 ? void 0 : _a.debug('Attempting to connect to PowerSync instance');
|
|
53
|
-
return super.connect(connector);
|
|
53
|
+
return super.connect(connector, options);
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
generateBucketStorageAdapter() {
|
|
@@ -89,4 +89,3 @@ Logs for shared sync worker will only be available in the shared worker context
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
PowerSyncDatabase.SHARED_MUTEX = new Mutex();
|
|
92
|
-
//# sourceMappingURL=PowerSyncDatabase.js.map
|
|
@@ -2,7 +2,7 @@ import * as Comlink from 'comlink';
|
|
|
2
2
|
import { WebStreamingSyncImplementation, WebStreamingSyncImplementationOptions } from './WebStreamingSyncImplementation';
|
|
3
3
|
import { SharedSyncImplementation } from '../../worker/sync/SharedSyncImplementation';
|
|
4
4
|
import { AbstractSharedSyncClientProvider } from '../../worker/sync/AbstractSharedSyncClientProvider';
|
|
5
|
-
import { PowerSyncCredentials, SyncStatusOptions } from '@powersync/common';
|
|
5
|
+
import { PowerSyncConnectionOptions, PowerSyncCredentials, SyncStatusOptions } from '@powersync/common';
|
|
6
6
|
/**
|
|
7
7
|
* The shared worker will trigger methods on this side of the message port
|
|
8
8
|
* via this client provider.
|
|
@@ -33,7 +33,7 @@ export declare class SharedWebStreamingSyncImplementation extends WebStreamingSy
|
|
|
33
33
|
* Starts the sync process, this effectively acts as a call to
|
|
34
34
|
* `connect` if not yet connected.
|
|
35
35
|
*/
|
|
36
|
-
connect(): Promise<void>;
|
|
36
|
+
connect(options?: PowerSyncConnectionOptions): Promise<void>;
|
|
37
37
|
disconnect(): Promise<void>;
|
|
38
38
|
getWriteCheckpoint(): Promise<string>;
|
|
39
39
|
hasCompletedSync(): Promise<boolean>;
|
|
@@ -135,10 +135,10 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
135
135
|
* Starts the sync process, this effectively acts as a call to
|
|
136
136
|
* `connect` if not yet connected.
|
|
137
137
|
*/
|
|
138
|
-
connect() {
|
|
138
|
+
connect(options) {
|
|
139
139
|
return __awaiter(this, void 0, void 0, function* () {
|
|
140
140
|
yield this.waitForReady();
|
|
141
|
-
return this.syncManager.connect();
|
|
141
|
+
return this.syncManager.connect(options);
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
144
|
disconnect() {
|
|
@@ -185,4 +185,3 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
|
-
//# sourceMappingURL=SharedWebStreamingSyncImplementation.js.map
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import { AbstractRemote } from '@powersync/common';
|
|
2
2
|
export declare class WebRemote extends AbstractRemote {
|
|
3
|
-
post(path: string, data: any, headers?: Record<string, string>): Promise<any>;
|
|
4
|
-
get(path: string, headers?: Record<string, string>): Promise<any>;
|
|
5
|
-
postStreaming(path: string, data: any, headers?: Record<string, string>, signal?: AbortSignal): Promise<any>;
|
|
6
3
|
}
|
|
@@ -1,134 +1,3 @@
|
|
|
1
|
-
|
|
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 { AbortOperation, AbstractRemote } from '@powersync/common';
|
|
1
|
+
import { AbstractRemote } from '@powersync/common';
|
|
11
2
|
export class WebRemote extends AbstractRemote {
|
|
12
|
-
post(path_1, data_1) {
|
|
13
|
-
return __awaiter(this, arguments, void 0, function* (path, data, headers = {}) {
|
|
14
|
-
const request = yield this.buildRequest(path);
|
|
15
|
-
const res = yield fetch(request.url, {
|
|
16
|
-
method: 'POST',
|
|
17
|
-
headers: Object.assign(Object.assign({}, headers), request.headers),
|
|
18
|
-
body: JSON.stringify(data)
|
|
19
|
-
});
|
|
20
|
-
if (!res.ok) {
|
|
21
|
-
throw new Error(`Received ${res.status} - ${res.statusText} when posting to ${path}: ${yield res.text()}}`);
|
|
22
|
-
}
|
|
23
|
-
return res.json();
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
get(path, headers) {
|
|
27
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
const request = yield this.buildRequest(path);
|
|
29
|
-
const res = yield fetch(request.url, {
|
|
30
|
-
method: 'GET',
|
|
31
|
-
headers: Object.assign(Object.assign({}, headers), request.headers)
|
|
32
|
-
});
|
|
33
|
-
if (!res.ok) {
|
|
34
|
-
throw new Error(`Received ${res.status} - ${res.statusText} when getting from ${path}: ${yield res.text()}}`);
|
|
35
|
-
}
|
|
36
|
-
return res.json();
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
postStreaming(path_1, data_1) {
|
|
40
|
-
return __awaiter(this, arguments, void 0, function* (path, data, headers = {}, signal) {
|
|
41
|
-
const request = yield this.buildRequest(path);
|
|
42
|
-
/**
|
|
43
|
-
* This abort controller will abort pending fetch requests.
|
|
44
|
-
* If the request has resolved, it will be used to close the readable stream.
|
|
45
|
-
* Which will cancel the network request.
|
|
46
|
-
*
|
|
47
|
-
* This nested controller is required since:
|
|
48
|
-
* Aborting the active fetch request while it is being consumed seems to throw
|
|
49
|
-
* an unhandled exception on the window level.
|
|
50
|
-
*/
|
|
51
|
-
const controller = new AbortController();
|
|
52
|
-
let requestResolved = false;
|
|
53
|
-
signal === null || signal === void 0 ? void 0 : signal.addEventListener('abort', () => {
|
|
54
|
-
var _a;
|
|
55
|
-
if (!requestResolved) {
|
|
56
|
-
// Only abort via the abort controller if the request has not resolved yet
|
|
57
|
-
controller.abort((_a = signal.reason) !== null && _a !== void 0 ? _a : new AbortOperation('Cancelling network request before it resolves. Abort signal has been received.'));
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
const res = yield fetch(request.url, {
|
|
61
|
-
method: 'POST',
|
|
62
|
-
headers: Object.assign(Object.assign({}, headers), request.headers),
|
|
63
|
-
body: JSON.stringify(data),
|
|
64
|
-
signal: controller.signal,
|
|
65
|
-
cache: 'no-store'
|
|
66
|
-
}).catch((ex) => {
|
|
67
|
-
if (ex.name == 'AbortError') {
|
|
68
|
-
throw new AbortOperation(`Pending fetch request to ${request.url} has been aborted.`);
|
|
69
|
-
}
|
|
70
|
-
throw ex;
|
|
71
|
-
});
|
|
72
|
-
if (!res) {
|
|
73
|
-
throw new Error('Fetch request was aborted');
|
|
74
|
-
}
|
|
75
|
-
requestResolved = true;
|
|
76
|
-
if (!res.ok || !res.body) {
|
|
77
|
-
const text = yield res.text();
|
|
78
|
-
this.logger.error(`Could not POST streaming to ${path} - ${res.status} - ${res.statusText}: ${text}`);
|
|
79
|
-
const error = new Error(`HTTP ${res.statusText}: ${text}`);
|
|
80
|
-
error.status = res.status;
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* The can-ndjson-stream does not handle aborted streams well.
|
|
85
|
-
* This will intercept the readable stream and close the stream if
|
|
86
|
-
* aborted.
|
|
87
|
-
*/
|
|
88
|
-
const reader = res.body.getReader();
|
|
89
|
-
// This will close the network request and read stream
|
|
90
|
-
const closeReader = () => __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
try {
|
|
92
|
-
yield reader.cancel();
|
|
93
|
-
}
|
|
94
|
-
catch (ex) {
|
|
95
|
-
// an error will throw if the reader hasn't been used yet
|
|
96
|
-
}
|
|
97
|
-
reader.releaseLock();
|
|
98
|
-
});
|
|
99
|
-
signal === null || signal === void 0 ? void 0 : signal.addEventListener('abort', () => {
|
|
100
|
-
closeReader();
|
|
101
|
-
});
|
|
102
|
-
const outputStream = new ReadableStream({
|
|
103
|
-
start: (controller) => {
|
|
104
|
-
const processStream = () => __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
while (!(signal === null || signal === void 0 ? void 0 : signal.aborted)) {
|
|
106
|
-
try {
|
|
107
|
-
const { done, value } = yield reader.read();
|
|
108
|
-
// When no more data needs to be consumed, close the stream
|
|
109
|
-
if (done) {
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
// Enqueue the next data chunk into our target stream
|
|
113
|
-
controller.enqueue(value);
|
|
114
|
-
}
|
|
115
|
-
catch (ex) {
|
|
116
|
-
this.logger.error('Caught exception when reading sync stream', ex);
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (!(signal === null || signal === void 0 ? void 0 : signal.aborted)) {
|
|
121
|
-
// Close the downstream readable stream
|
|
122
|
-
yield closeReader();
|
|
123
|
-
}
|
|
124
|
-
controller.close();
|
|
125
|
-
});
|
|
126
|
-
processStream();
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
// Create a new response out of the intercepted stream
|
|
130
|
-
return new Response(outputStream).body;
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
3
|
}
|
|
134
|
-
//# sourceMappingURL=WebRemote.js.map
|
package/lib/src/index.js
CHANGED
|
@@ -6,4 +6,3 @@ export * from './db/sync/SharedWebStreamingSyncImplementation';
|
|
|
6
6
|
export * from './db/adapters/wa-sqlite/WASQLiteDBAdapter';
|
|
7
7
|
export * from './db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory';
|
|
8
8
|
export * from './db/adapters/AbstractWebPowerSyncDatabaseOpenFactory';
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -9,15 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import '@journeyapps/wa-sqlite';
|
|
11
11
|
import * as Comlink from 'comlink';
|
|
12
|
-
import { v4 as uuid } from 'uuid';
|
|
13
12
|
import { _openDB } from './open-db';
|
|
14
13
|
const _self = self;
|
|
15
14
|
const DBMap = new Map();
|
|
16
15
|
const OPEN_DB_LOCK = 'open-wasqlite-db';
|
|
16
|
+
let nextClientId = 1;
|
|
17
17
|
const openDB = (dbFileName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
18
|
// Prevent multiple simultaneous opens from causing race conditions
|
|
19
19
|
return navigator.locks.request(OPEN_DB_LOCK, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
const clientId =
|
|
20
|
+
const clientId = nextClientId++;
|
|
21
21
|
if (!DBMap.has(dbFileName)) {
|
|
22
22
|
const clientIds = new Set();
|
|
23
23
|
const connection = yield _openDB(dbFileName);
|
|
@@ -55,4 +55,3 @@ addEventListener('unload', () => {
|
|
|
55
55
|
(_a = db.close) === null || _a === void 0 ? void 0 : _a.call(db);
|
|
56
56
|
}));
|
|
57
57
|
});
|
|
58
|
-
//# sourceMappingURL=SharedWASQLiteDB.worker.js.map
|
|
@@ -10,4 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import * as Comlink from 'comlink';
|
|
11
11
|
import { _openDB } from './open-db';
|
|
12
12
|
Comlink.expose((dbFileName) => __awaiter(void 0, void 0, void 0, function* () { return Comlink.proxy(yield _openDB(dbFileName)); }));
|
|
13
|
-
//# sourceMappingURL=WASQLiteDB.worker.js.map
|
|
@@ -17,7 +17,7 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
17
17
|
import * as SQLite from '@journeyapps/wa-sqlite';
|
|
18
18
|
import '@journeyapps/wa-sqlite';
|
|
19
19
|
import * as Comlink from 'comlink';
|
|
20
|
-
|
|
20
|
+
let nextId = 1;
|
|
21
21
|
export function _openDB(dbFileName) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
23
|
const { default: moduleFactory } = yield import('@journeyapps/wa-sqlite/dist/wa-sqlite-async.mjs');
|
|
@@ -35,7 +35,7 @@ export function _openDB(dbFileName) {
|
|
|
35
35
|
Array.from(listeners.values()).forEach((l) => l(opType, tableName, rowId));
|
|
36
36
|
});
|
|
37
37
|
const registerOnTableChange = (callback) => {
|
|
38
|
-
const id =
|
|
38
|
+
const id = nextId++;
|
|
39
39
|
listeners.set(id, callback);
|
|
40
40
|
return Comlink.proxy(() => {
|
|
41
41
|
listeners.delete(id);
|
|
@@ -190,4 +190,3 @@ export function _openDB(dbFileName) {
|
|
|
190
190
|
};
|
|
191
191
|
});
|
|
192
192
|
}
|
|
193
|
-
//# sourceMappingURL=open-db.js.map
|
|
@@ -28,4 +28,3 @@ export function openWorkerDatabasePort(workerIdentifier, multipleTabs = true) {
|
|
|
28
28
|
export function getWorkerDatabaseOpener(workerIdentifier, multipleTabs = true) {
|
|
29
29
|
return Comlink.wrap(openWorkerDatabasePort(workerIdentifier, multipleTabs));
|
|
30
30
|
}
|
|
31
|
-
//# sourceMappingURL=open-worker-database.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Comlink from 'comlink';
|
|
2
2
|
import { ILogger } from 'js-logger';
|
|
3
|
-
import { AbstractStreamingSyncImplementation, StreamingSyncImplementation, BaseObserver, LockOptions, StreamingSyncImplementationListener, SyncStatus, SyncStatusOptions } from '@powersync/common';
|
|
3
|
+
import { AbstractStreamingSyncImplementation, StreamingSyncImplementation, BaseObserver, LockOptions, StreamingSyncImplementationListener, SyncStatus, SyncStatusOptions, PowerSyncConnectionOptions } from '@powersync/common';
|
|
4
4
|
import { WebStreamingSyncImplementationOptions } from '../../db/sync/WebStreamingSyncImplementation';
|
|
5
5
|
import { AbstractSharedSyncClientProvider } from './AbstractSharedSyncClientProvider';
|
|
6
6
|
/**
|
|
@@ -60,7 +60,7 @@ export declare class SharedSyncImplementation extends BaseObserver<SharedSyncImp
|
|
|
60
60
|
* The connection will simply be reconnected whenever a new tab
|
|
61
61
|
* connects.
|
|
62
62
|
*/
|
|
63
|
-
connect(): Promise<any>;
|
|
63
|
+
connect(options?: PowerSyncConnectionOptions): Promise<any>;
|
|
64
64
|
disconnect(): Promise<any>;
|
|
65
65
|
/**
|
|
66
66
|
* Adds a new client tab's message port to the list of connected ports
|
|
@@ -149,11 +149,11 @@ export class SharedSyncImplementation extends BaseObserver {
|
|
|
149
149
|
* The connection will simply be reconnected whenever a new tab
|
|
150
150
|
* connects.
|
|
151
151
|
*/
|
|
152
|
-
connect() {
|
|
152
|
+
connect(options) {
|
|
153
153
|
return __awaiter(this, void 0, void 0, function* () {
|
|
154
154
|
yield this.waitForReady();
|
|
155
155
|
// This effectively queues connect and disconnect calls. Ensuring multiple tabs' requests are synchronized
|
|
156
|
-
return navigator.locks.request('shared-sync-connect', () => { var _a; return (_a = this.syncStreamClient) === null || _a === void 0 ? void 0 : _a.connect(); });
|
|
156
|
+
return navigator.locks.request('shared-sync-connect', () => { var _a; return (_a = this.syncStreamClient) === null || _a === void 0 ? void 0 : _a.connect(options); });
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
disconnect() {
|
|
@@ -245,4 +245,3 @@ export class SharedSyncImplementation extends BaseObserver {
|
|
|
245
245
|
this.updateAllStatuses(status);
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
|
-
//# sourceMappingURL=SharedSyncImplementation.js.map
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import * as Comlink from 'comlink';
|
|
2
2
|
import { SharedSyncImplementation, SharedSyncClientEvent } from './SharedSyncImplementation';
|
|
3
3
|
import Logger from 'js-logger';
|
|
4
|
+
import { Buffer } from 'buffer';
|
|
5
|
+
if (typeof self.Buffer == 'undefined') {
|
|
6
|
+
self.Buffer = Buffer;
|
|
7
|
+
}
|
|
4
8
|
const _self = self;
|
|
5
9
|
Logger.useDefaults();
|
|
6
10
|
const sharedSyncImplementation = new SharedSyncImplementation();
|
|
@@ -20,4 +24,3 @@ _self.onconnect = function (event) {
|
|
|
20
24
|
Comlink.expose(sharedSyncImplementation, port);
|
|
21
25
|
sharedSyncImplementation.addPort(port);
|
|
22
26
|
};
|
|
23
|
-
//# sourceMappingURL=SharedSyncImplementation.worker.js.map
|