@powersync/web 0.5.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/LICENSE +201 -0
- package/README.md +55 -0
- package/lib/src/db/PowerSyncDatabase.d.ts +43 -0
- package/lib/src/db/PowerSyncDatabase.js +92 -0
- package/lib/src/db/PowerSyncDatabase.js.map +1 -0
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.d.ts +23 -0
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js +57 -0
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js.map +1 -0
- package/lib/src/db/adapters/SSRDBAdapter.d.ts +29 -0
- package/lib/src/db/adapters/SSRDBAdapter.js +86 -0
- package/lib/src/db/adapters/SSRDBAdapter.js.map +1 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.d.ts +56 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.js +197 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.js.map +1 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.d.ts +6 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js +12 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js.map +1 -0
- package/lib/src/db/sync/SSRWebStreamingSyncImplementation.d.ts +8 -0
- package/lib/src/db/sync/SSRWebStreamingSyncImplementation.js +14 -0
- package/lib/src/db/sync/SSRWebStreamingSyncImplementation.js.map +1 -0
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.d.ts +47 -0
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js +188 -0
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js.map +1 -0
- package/lib/src/db/sync/WebRemote.d.ts +6 -0
- package/lib/src/db/sync/WebRemote.js +134 -0
- package/lib/src/db/sync/WebRemote.js.map +1 -0
- package/lib/src/db/sync/WebStreamingSyncImplementation.d.ts +11 -0
- package/lib/src/db/sync/WebStreamingSyncImplementation.js +16 -0
- package/lib/src/db/sync/WebStreamingSyncImplementation.js.map +1 -0
- package/lib/src/index.d.ts +8 -0
- package/lib/src/index.js +9 -0
- package/lib/src/index.js.map +1 -0
- package/lib/src/worker/db/SharedWASQLiteDB.worker.d.ts +1 -0
- package/lib/src/worker/db/SharedWASQLiteDB.worker.js +58 -0
- package/lib/src/worker/db/SharedWASQLiteDB.worker.js.map +1 -0
- package/lib/src/worker/db/WASQLiteDB.worker.d.ts +1 -0
- package/lib/src/worker/db/WASQLiteDB.worker.js +13 -0
- package/lib/src/worker/db/WASQLiteDB.worker.js.map +1 -0
- package/lib/src/worker/db/open-db.d.ts +20 -0
- package/lib/src/worker/db/open-db.js +193 -0
- package/lib/src/worker/db/open-db.js.map +1 -0
- package/lib/src/worker/db/open-worker-database.d.ts +11 -0
- package/lib/src/worker/db/open-worker-database.js +31 -0
- package/lib/src/worker/db/open-worker-database.js.map +1 -0
- package/lib/src/worker/sync/AbstractSharedSyncClientProvider.d.ts +17 -0
- package/lib/src/worker/sync/AbstractSharedSyncClientProvider.js +6 -0
- package/lib/src/worker/sync/AbstractSharedSyncClientProvider.js.map +1 -0
- package/lib/src/worker/sync/BroadcastLogger.d.ts +37 -0
- package/lib/src/worker/sync/BroadcastLogger.js +108 -0
- package/lib/src/worker/sync/BroadcastLogger.js.map +1 -0
- package/lib/src/worker/sync/SharedSyncImplementation.d.ts +88 -0
- package/lib/src/worker/sync/SharedSyncImplementation.js +248 -0
- package/lib/src/worker/sync/SharedSyncImplementation.js.map +1 -0
- package/lib/src/worker/sync/SharedSyncImplementation.worker.d.ts +1 -0
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js +23 -0
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { BaseObserver, DBAdapter, DBAdapterListener, DBLockOptions, LockContext, PowerSyncOpenFactoryOptions, QueryResult, Transaction } from '@powersync/common';
|
|
2
|
+
export type WASQLiteFlags = {
|
|
3
|
+
enableMultiTabs?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export interface WASQLiteDBAdapterOptions extends Omit<PowerSyncOpenFactoryOptions, 'schema'> {
|
|
6
|
+
flags?: WASQLiteFlags;
|
|
7
|
+
/**
|
|
8
|
+
* Use an existing port to an initialized worker.
|
|
9
|
+
* A worker will be initialized if none is provided
|
|
10
|
+
*/
|
|
11
|
+
workerPort?: MessagePort;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Adapter for WA-SQLite
|
|
15
|
+
*/
|
|
16
|
+
export declare class WASQLiteDBAdapter extends BaseObserver<DBAdapterListener> implements DBAdapter {
|
|
17
|
+
protected options: WASQLiteDBAdapterOptions;
|
|
18
|
+
private initialized;
|
|
19
|
+
private logger;
|
|
20
|
+
private dbGetHelpers;
|
|
21
|
+
private workerMethods;
|
|
22
|
+
constructor(options: WASQLiteDBAdapterOptions);
|
|
23
|
+
get name(): string;
|
|
24
|
+
protected get flags(): WASQLiteFlags;
|
|
25
|
+
getWorker(): void;
|
|
26
|
+
protected init(): Promise<void>;
|
|
27
|
+
execute(query: string, params?: any[] | undefined): Promise<QueryResult>;
|
|
28
|
+
executeBatch(query: string, params?: any[][]): Promise<QueryResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Wraps the worker execute function, awaiting for it to be available
|
|
31
|
+
*/
|
|
32
|
+
private _execute;
|
|
33
|
+
/**
|
|
34
|
+
* Wraps the worker executeBatch function, awaiting for it to be available
|
|
35
|
+
*/
|
|
36
|
+
private _executeBatch;
|
|
37
|
+
/**
|
|
38
|
+
* Attempts to close the connection.
|
|
39
|
+
* Shared workers might not actually close the connection if other
|
|
40
|
+
* tabs are still using it.
|
|
41
|
+
*/
|
|
42
|
+
close(): void;
|
|
43
|
+
getAll<T>(sql: string, parameters?: any[] | undefined): Promise<T[]>;
|
|
44
|
+
getOptional<T>(sql: string, parameters?: any[] | undefined): Promise<T | null>;
|
|
45
|
+
get<T>(sql: string, parameters?: any[] | undefined): Promise<T>;
|
|
46
|
+
readLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions | undefined): Promise<T>;
|
|
47
|
+
writeLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions | undefined): Promise<T>;
|
|
48
|
+
protected acquireLock(callback: () => Promise<any>): Promise<any>;
|
|
49
|
+
readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions | undefined): Promise<T>;
|
|
50
|
+
writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions | undefined): Promise<T>;
|
|
51
|
+
/**
|
|
52
|
+
* Wraps a lock context into a transaction context
|
|
53
|
+
*/
|
|
54
|
+
private wrapTransaction;
|
|
55
|
+
private generateDBHelpers;
|
|
56
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
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 { BaseObserver } from '@powersync/common';
|
|
11
|
+
import * as Comlink from 'comlink';
|
|
12
|
+
import Logger from 'js-logger';
|
|
13
|
+
import { getWorkerDatabaseOpener } from '../../../worker/db/open-worker-database';
|
|
14
|
+
/**
|
|
15
|
+
* Adapter for WA-SQLite
|
|
16
|
+
*/
|
|
17
|
+
export class WASQLiteDBAdapter extends BaseObserver {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
super();
|
|
20
|
+
this.options = options;
|
|
21
|
+
/**
|
|
22
|
+
* Wraps the worker execute function, awaiting for it to be available
|
|
23
|
+
*/
|
|
24
|
+
this._execute = (sql, bindings) => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
yield this.initialized;
|
|
26
|
+
const result = yield this.workerMethods.execute(sql, bindings);
|
|
27
|
+
return Object.assign(Object.assign({}, result), { rows: Object.assign(Object.assign({}, result.rows), { item: (idx) => result.rows._array[idx] }) });
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Wraps the worker executeBatch function, awaiting for it to be available
|
|
31
|
+
*/
|
|
32
|
+
this._executeBatch = (query, params) => __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
yield this.initialized;
|
|
34
|
+
const result = yield this.workerMethods.executeBatch(query, params);
|
|
35
|
+
return Object.assign(Object.assign({}, result), { rows: undefined });
|
|
36
|
+
});
|
|
37
|
+
this.logger = Logger.get('WASQLite');
|
|
38
|
+
this.dbGetHelpers = null;
|
|
39
|
+
this.workerMethods = null;
|
|
40
|
+
this.initialized = this.init();
|
|
41
|
+
this.dbGetHelpers = this.generateDBHelpers({ execute: this._execute.bind(this) });
|
|
42
|
+
}
|
|
43
|
+
get name() {
|
|
44
|
+
return this.options.dbFilename;
|
|
45
|
+
}
|
|
46
|
+
get flags() {
|
|
47
|
+
var _a;
|
|
48
|
+
return (_a = this.options.flags) !== null && _a !== void 0 ? _a : {};
|
|
49
|
+
}
|
|
50
|
+
getWorker() { }
|
|
51
|
+
init() {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const { enableMultiTabs } = this.flags;
|
|
54
|
+
if (!enableMultiTabs) {
|
|
55
|
+
this.logger.warn('Multiple tabs are not enabled in this browser');
|
|
56
|
+
}
|
|
57
|
+
const dbOpener = this.options.workerPort
|
|
58
|
+
? Comlink.wrap(this.options.workerPort)
|
|
59
|
+
: getWorkerDatabaseOpener(this.options.dbFilename, enableMultiTabs);
|
|
60
|
+
this.workerMethods = yield dbOpener(this.options.dbFilename);
|
|
61
|
+
this.workerMethods.registerOnTableChange(Comlink.proxy((opType, tableName, rowId) => {
|
|
62
|
+
this.iterateListeners((cb) => { var _a; return (_a = cb.tablesUpdated) === null || _a === void 0 ? void 0 : _a.call(cb, { opType, table: tableName, rowId }); });
|
|
63
|
+
}));
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
execute(query, params) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
return this.writeLock((ctx) => ctx.execute(query, params));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
executeBatch(query, params) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
return this.writeLock((ctx) => this._executeBatch(query, params));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Attempts to close the connection.
|
|
78
|
+
* Shared workers might not actually close the connection if other
|
|
79
|
+
* tabs are still using it.
|
|
80
|
+
*/
|
|
81
|
+
close() {
|
|
82
|
+
var _a, _b;
|
|
83
|
+
(_b = (_a = this.workerMethods) === null || _a === void 0 ? void 0 : _a.close) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
84
|
+
}
|
|
85
|
+
getAll(sql, parameters) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
yield this.initialized;
|
|
88
|
+
return this.dbGetHelpers.getAll(sql, parameters);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
getOptional(sql, parameters) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
yield this.initialized;
|
|
94
|
+
return this.dbGetHelpers.getOptional(sql, parameters);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
get(sql, parameters) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
yield this.initialized;
|
|
100
|
+
return this.dbGetHelpers.get(sql, parameters);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
readLock(fn, options) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
yield this.initialized;
|
|
106
|
+
return this.acquireLock(() => __awaiter(this, void 0, void 0, function* () { return fn(this.generateDBHelpers({ execute: this._execute })); }));
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
writeLock(fn, options) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
yield this.initialized;
|
|
112
|
+
return this.acquireLock(() => __awaiter(this, void 0, void 0, function* () { return fn(this.generateDBHelpers({ execute: this._execute })); }));
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
acquireLock(callback) {
|
|
116
|
+
return navigator.locks.request(`db-lock-${this.options.dbFilename}`, callback);
|
|
117
|
+
}
|
|
118
|
+
readTransaction(fn, options) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
return this.readLock(this.wrapTransaction(fn));
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
writeTransaction(fn, options) {
|
|
124
|
+
return this.writeLock(this.wrapTransaction(fn));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Wraps a lock context into a transaction context
|
|
128
|
+
*/
|
|
129
|
+
wrapTransaction(cb) {
|
|
130
|
+
return (tx) => __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
yield this._execute('BEGIN TRANSACTION');
|
|
132
|
+
let finalized = false;
|
|
133
|
+
const commit = () => __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
if (finalized) {
|
|
135
|
+
return { rowsAffected: 0 };
|
|
136
|
+
}
|
|
137
|
+
finalized = true;
|
|
138
|
+
return this._execute('COMMIT');
|
|
139
|
+
});
|
|
140
|
+
const rollback = () => {
|
|
141
|
+
finalized = true;
|
|
142
|
+
return this._execute('ROLLBACK');
|
|
143
|
+
};
|
|
144
|
+
try {
|
|
145
|
+
const result = yield cb(Object.assign(Object.assign({}, tx), { commit,
|
|
146
|
+
rollback }));
|
|
147
|
+
if (!finalized) {
|
|
148
|
+
yield commit();
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
catch (ex) {
|
|
153
|
+
this.logger.debug('Caught ex in transaction', ex);
|
|
154
|
+
yield rollback();
|
|
155
|
+
throw ex;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
generateDBHelpers(tx) {
|
|
160
|
+
return Object.assign(Object.assign({}, tx), {
|
|
161
|
+
/**
|
|
162
|
+
* Execute a read-only query and return results
|
|
163
|
+
*/
|
|
164
|
+
getAll(sql, parameters) {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
var _a, _b;
|
|
167
|
+
const res = yield tx.execute(sql, parameters);
|
|
168
|
+
return (_b = (_a = res.rows) === null || _a === void 0 ? void 0 : _a._array) !== null && _b !== void 0 ? _b : [];
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
/**
|
|
172
|
+
* Execute a read-only query and return the first result, or null if the ResultSet is empty.
|
|
173
|
+
*/
|
|
174
|
+
getOptional(sql, parameters) {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
var _a, _b;
|
|
177
|
+
const res = yield tx.execute(sql, parameters);
|
|
178
|
+
return (_b = (_a = res.rows) === null || _a === void 0 ? void 0 : _a.item(0)) !== null && _b !== void 0 ? _b : null;
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
/**
|
|
182
|
+
* Execute a read-only query and return the first result, error if the ResultSet is empty.
|
|
183
|
+
*/
|
|
184
|
+
get(sql, parameters) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
var _a;
|
|
187
|
+
const res = yield tx.execute(sql, parameters);
|
|
188
|
+
const first = (_a = res.rows) === null || _a === void 0 ? void 0 : _a.item(0);
|
|
189
|
+
if (!first) {
|
|
190
|
+
throw new Error('Result set is empty');
|
|
191
|
+
}
|
|
192
|
+
return first;
|
|
193
|
+
});
|
|
194
|
+
} });
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=WASQLiteDBAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WASQLiteDBAdapter.js","sourceRoot":"","sources":["../../../../../src/db/adapters/wa-sqlite/WASQLiteDBAdapter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,YAAY,EASb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,MAAmB,MAAM,WAAW,CAAC;AAE5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAelF;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,YAA+B;IAMpE,YAAsB,OAAiC;QACrD,KAAK,EAAE,CAAC;QADY,YAAO,GAAP,OAAO,CAA0B;QA8CvD;;WAEG;QACK,aAAQ,GAAG,CAAO,GAAW,EAAE,QAAgB,EAAwB,EAAE;YAC/E,MAAM,IAAI,CAAC,WAAW,CAAC;YACvB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAc,CAAC,OAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YACjE,uCACK,MAAM,KACT,IAAI,kCACC,MAAM,CAAC,IAAI,KACd,IAAI,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAEhD;QACJ,CAAC,CAAA,CAAC;QAEF;;WAEG;QACK,kBAAa,GAAG,CAAO,KAAa,EAAE,MAAc,EAAwB,EAAE;YACpF,MAAM,IAAI,CAAC,WAAW,CAAC;YACvB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,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,MAAA,GAAG,CAAC,IAAI,0CAAE,IAAI,CAAC,CAAC,CAAC,mCAAI,IAAI,CAAC;gBACnC,CAAC;aAAA;YAED;;eAEG;YACG,GAAG,CAAI,GAAW,EAAE,UAAkB;;;oBAC1C,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;oBAC9C,MAAM,KAAK,GAAG,MAAA,GAAG,CAAC,IAAI,0CAAE,IAAI,CAAC,CAAC,CAAC,CAAC;oBAChC,IAAI,CAAC,KAAK,EAAE,CAAC;wBACX,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;oBACzC,CAAC;oBACD,OAAO,KAAK,CAAC;gBACf,CAAC;aAAA,IACD;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AbstractPowerSyncDatabase, DBAdapter, PowerSyncDatabaseOptions } from '@powersync/common';
|
|
2
|
+
import { AbstractWebPowerSyncDatabaseOpenFactory } from '../AbstractWebPowerSyncDatabaseOpenFactory';
|
|
3
|
+
export declare class WASQLitePowerSyncDatabaseOpenFactory extends AbstractWebPowerSyncDatabaseOpenFactory {
|
|
4
|
+
protected openDB(): DBAdapter;
|
|
5
|
+
generateInstance(options: PowerSyncDatabaseOptions): AbstractPowerSyncDatabase;
|
|
6
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PowerSyncDatabase } from '../../../db/PowerSyncDatabase';
|
|
2
|
+
import { WASQLiteDBAdapter } from './WASQLiteDBAdapter';
|
|
3
|
+
import { AbstractWebPowerSyncDatabaseOpenFactory } from '../AbstractWebPowerSyncDatabaseOpenFactory';
|
|
4
|
+
export class WASQLitePowerSyncDatabaseOpenFactory extends AbstractWebPowerSyncDatabaseOpenFactory {
|
|
5
|
+
openDB() {
|
|
6
|
+
return new WASQLiteDBAdapter(Object.assign(Object.assign({}, this.options), { flags: this.resolveDBFlags() }));
|
|
7
|
+
}
|
|
8
|
+
generateInstance(options) {
|
|
9
|
+
return new PowerSyncDatabase(options);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=WASQLitePowerSyncDatabaseOpenFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WASQLitePowerSyncDatabaseOpenFactory.js","sourceRoot":"","sources":["../../../../../src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,uCAAuC,EAAE,MAAM,4CAA4C,CAAC;AAErG,MAAM,OAAO,oCAAqC,SAAQ,uCAAuC;IACrF,MAAM;QACd,OAAO,IAAI,iBAAiB,iCAAM,IAAI,CAAC,OAAO,KAAE,KAAK,EAAE,IAAI,CAAC,cAAc,EAAE,IAAG,CAAC;IAClF,CAAC;IAED,gBAAgB,CAAC,OAAiC;QAChD,OAAO,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AbstractStreamingSyncImplementation, AbstractStreamingSyncImplementationOptions, LockOptions } from '@powersync/common';
|
|
2
|
+
import { Mutex } from 'async-mutex';
|
|
3
|
+
export declare class SSRStreamingSyncImplementation extends AbstractStreamingSyncImplementation {
|
|
4
|
+
syncMutex: Mutex;
|
|
5
|
+
crudMutex: Mutex;
|
|
6
|
+
constructor(options: AbstractStreamingSyncImplementationOptions);
|
|
7
|
+
obtainLock<T>(lockOptions: LockOptions<T>): Promise<T>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AbstractStreamingSyncImplementation, LockType } from '@powersync/common';
|
|
2
|
+
import { Mutex } from 'async-mutex';
|
|
3
|
+
export class SSRStreamingSyncImplementation extends AbstractStreamingSyncImplementation {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
super(options);
|
|
6
|
+
this.syncMutex = new Mutex();
|
|
7
|
+
this.crudMutex = new Mutex();
|
|
8
|
+
}
|
|
9
|
+
obtainLock(lockOptions) {
|
|
10
|
+
const mutex = lockOptions.type == LockType.CRUD ? this.crudMutex : this.syncMutex;
|
|
11
|
+
return mutex.runExclusive(lockOptions.callback);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=SSRWebStreamingSyncImplementation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SSRWebStreamingSyncImplementation.js","sourceRoot":"","sources":["../../../../src/db/sync/SSRWebStreamingSyncImplementation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mCAAmC,EAGnC,QAAQ,EACT,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,MAAM,OAAO,8BAA+B,SAAQ,mCAAmC;IAIrF,YAAY,OAAmD;QAC7D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,IAAI,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,IAAI,KAAK,EAAE,CAAC;IAC/B,CAAC;IAED,UAAU,CAAI,WAA2B;QACvC,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;QAClF,OAAO,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAClD,CAAC;CACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as Comlink from 'comlink';
|
|
2
|
+
import { WebStreamingSyncImplementation, WebStreamingSyncImplementationOptions } from './WebStreamingSyncImplementation';
|
|
3
|
+
import { SharedSyncImplementation } from '../../worker/sync/SharedSyncImplementation';
|
|
4
|
+
import { AbstractSharedSyncClientProvider } from '../../worker/sync/AbstractSharedSyncClientProvider';
|
|
5
|
+
import { PowerSyncCredentials, SyncStatusOptions } from '@powersync/common';
|
|
6
|
+
/**
|
|
7
|
+
* The shared worker will trigger methods on this side of the message port
|
|
8
|
+
* via this client provider.
|
|
9
|
+
*/
|
|
10
|
+
declare class SharedSyncClientProvider extends AbstractSharedSyncClientProvider {
|
|
11
|
+
protected options: WebStreamingSyncImplementationOptions;
|
|
12
|
+
statusChanged: (status: SyncStatusOptions) => void;
|
|
13
|
+
constructor(options: WebStreamingSyncImplementationOptions, statusChanged: (status: SyncStatusOptions) => void);
|
|
14
|
+
fetchCredentials(): Promise<PowerSyncCredentials | null>;
|
|
15
|
+
uploadCrud(): Promise<void>;
|
|
16
|
+
get logger(): import("js-logger").ILogger | undefined;
|
|
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
|
+
export declare class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplementation {
|
|
27
|
+
protected syncManager: Comlink.Remote<SharedSyncImplementation>;
|
|
28
|
+
protected clientProvider: SharedSyncClientProvider;
|
|
29
|
+
protected messagePort: MessagePort;
|
|
30
|
+
protected isInitialized: Promise<void>;
|
|
31
|
+
constructor(options: WebStreamingSyncImplementationOptions);
|
|
32
|
+
/**
|
|
33
|
+
* Starts the sync process, this effectively acts as a call to
|
|
34
|
+
* `connect` if not yet connected.
|
|
35
|
+
*/
|
|
36
|
+
connect(): Promise<void>;
|
|
37
|
+
disconnect(): Promise<void>;
|
|
38
|
+
getWriteCheckpoint(): Promise<string>;
|
|
39
|
+
hasCompletedSync(): Promise<boolean>;
|
|
40
|
+
dispose(): Promise<void>;
|
|
41
|
+
waitForReady(): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Used in tests to force a connection states
|
|
44
|
+
*/
|
|
45
|
+
private _testUpdateStatus;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,188 @@
|
|
|
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 * as Comlink from 'comlink';
|
|
11
|
+
import { WebStreamingSyncImplementation } from './WebStreamingSyncImplementation';
|
|
12
|
+
import { SharedSyncClientEvent } from '../../worker/sync/SharedSyncImplementation';
|
|
13
|
+
import { AbstractSharedSyncClientProvider } from '../../worker/sync/AbstractSharedSyncClientProvider';
|
|
14
|
+
import { openWorkerDatabasePort } from '../../worker/db/open-worker-database';
|
|
15
|
+
/**
|
|
16
|
+
* The shared worker will trigger methods on this side of the message port
|
|
17
|
+
* via this client provider.
|
|
18
|
+
*/
|
|
19
|
+
class SharedSyncClientProvider extends AbstractSharedSyncClientProvider {
|
|
20
|
+
constructor(options, statusChanged) {
|
|
21
|
+
super();
|
|
22
|
+
this.options = options;
|
|
23
|
+
this.statusChanged = statusChanged;
|
|
24
|
+
}
|
|
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
|
+
});
|
|
43
|
+
}
|
|
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
|
+
});
|
|
52
|
+
}
|
|
53
|
+
get logger() {
|
|
54
|
+
return this.options.logger;
|
|
55
|
+
}
|
|
56
|
+
trace(...x) {
|
|
57
|
+
var _a;
|
|
58
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(...x);
|
|
59
|
+
}
|
|
60
|
+
debug(...x) {
|
|
61
|
+
var _a;
|
|
62
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(...x);
|
|
63
|
+
}
|
|
64
|
+
info(...x) {
|
|
65
|
+
var _a;
|
|
66
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(...x);
|
|
67
|
+
}
|
|
68
|
+
log(...x) {
|
|
69
|
+
var _a;
|
|
70
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(...x);
|
|
71
|
+
}
|
|
72
|
+
warn(...x) {
|
|
73
|
+
var _a;
|
|
74
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn(...x);
|
|
75
|
+
}
|
|
76
|
+
error(...x) {
|
|
77
|
+
var _a;
|
|
78
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(...x);
|
|
79
|
+
}
|
|
80
|
+
time(label) {
|
|
81
|
+
var _a;
|
|
82
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.time(label);
|
|
83
|
+
}
|
|
84
|
+
timeEnd(label) {
|
|
85
|
+
var _a;
|
|
86
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.timeEnd(label);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplementation {
|
|
90
|
+
constructor(options) {
|
|
91
|
+
super(options);
|
|
92
|
+
/**
|
|
93
|
+
* Configure or connect to the shared sync worker.
|
|
94
|
+
* This worker will manage all syncing operations remotely.
|
|
95
|
+
*/
|
|
96
|
+
const syncWorker = new SharedWorker(new URL('../../worker/sync/SharedSyncImplementation.worker.js', import.meta.url), {
|
|
97
|
+
/* @vite-ignore */
|
|
98
|
+
name: `shared-sync-${this.webOptions.identifier}`,
|
|
99
|
+
type: 'module'
|
|
100
|
+
});
|
|
101
|
+
this.messagePort = syncWorker.port;
|
|
102
|
+
this.syncManager = Comlink.wrap(this.messagePort);
|
|
103
|
+
this.triggerCrudUpload = this.syncManager.triggerCrudUpload;
|
|
104
|
+
/**
|
|
105
|
+
* Opens MessagePort to the existing shared DB worker.
|
|
106
|
+
* The sync worker cannot initiate connections directly to the
|
|
107
|
+
* DB worker, but a port to the DB worker can be transferred to the
|
|
108
|
+
* sync worker.
|
|
109
|
+
*/
|
|
110
|
+
const { crudUploadThrottleMs, identifier, retryDelayMs } = this.options;
|
|
111
|
+
const dbOpenerPort = openWorkerDatabasePort(this.options.identifier, true);
|
|
112
|
+
this.isInitialized = this.syncManager.init(Comlink.transfer(dbOpenerPort, [dbOpenerPort]), {
|
|
113
|
+
dbName: this.options.identifier,
|
|
114
|
+
streamOptions: {
|
|
115
|
+
crudUploadThrottleMs,
|
|
116
|
+
identifier,
|
|
117
|
+
retryDelayMs,
|
|
118
|
+
flags: this.webOptions.flags
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
/**
|
|
122
|
+
* Pass along any sync status updates to this listener
|
|
123
|
+
*/
|
|
124
|
+
this.clientProvider = new SharedSyncClientProvider(this.webOptions, (status) => {
|
|
125
|
+
this.iterateListeners((l) => this.updateSyncStatus(status));
|
|
126
|
+
});
|
|
127
|
+
/**
|
|
128
|
+
* The sync worker will call this client provider when it needs
|
|
129
|
+
* to fetch credentials or upload data.
|
|
130
|
+
* This performs bi-directional method calling.
|
|
131
|
+
*/
|
|
132
|
+
Comlink.expose(this.clientProvider, this.messagePort);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Starts the sync process, this effectively acts as a call to
|
|
136
|
+
* `connect` if not yet connected.
|
|
137
|
+
*/
|
|
138
|
+
connect() {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
yield this.waitForReady();
|
|
141
|
+
return this.syncManager.connect();
|
|
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
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Used in tests to force a connection states
|
|
181
|
+
*/
|
|
182
|
+
_testUpdateStatus(status) {
|
|
183
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
+
return this.syncManager['_testUpdateAllStatuses'](status.toJSON());
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=SharedWebStreamingSyncImplementation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SharedWebStreamingSyncImplementation.js","sourceRoot":"","sources":["../../../../src/db/sync/SharedWebStreamingSyncImplementation.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EACL,8BAA8B,EAE/B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAEL,qBAAqB,EAEtB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,gCAAgC,EAAE,MAAM,oDAAoD,CAAC;AAEtG,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAE9E;;;GAGG;AACH,MAAM,wBAAyB,SAAQ,gCAAgC;IACrE,YACY,OAA8C,EACjD,aAAkD;QAEzD,KAAK,EAAE,CAAC;QAHE,YAAO,GAAP,OAAO,CAAuC;QACjD,kBAAa,GAAb,aAAa,CAAqC;IAG3D,CAAC;IAEK,gBAAgB;;YACpB,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;YAC/D,IAAI,WAAW,IAAI,IAA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WAAmB,CAAC,wBAAwB,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QAC9E,CAAC;KAAA;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AbstractRemote } from '@powersync/common';
|
|
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
|
+
}
|