@powersync/web 0.0.0-dev-20251111122755 → 0.0.0-dev-20251119142638
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/dist/index.umd.js +39 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/worker/SharedSyncImplementation.umd.js +35 -12
- package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
- package/dist/worker/WASQLiteDB.umd.js +220 -54
- package/dist/worker/WASQLiteDB.umd.js.map +1 -1
- package/lib/package.json +2 -2
- package/lib/src/db/adapters/AsyncDatabaseConnection.d.ts +2 -0
- package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.d.ts +1 -1
- package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.js +8 -2
- package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.d.ts +2 -0
- package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.js +6 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.d.ts +17 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js +25 -0
- package/lib/src/worker/db/SharedWASQLiteConnection.d.ts +41 -0
- package/lib/src/worker/db/SharedWASQLiteConnection.js +89 -0
- package/lib/src/worker/db/WASQLiteDB.worker.js +22 -39
- package/lib/src/worker/db/WorkerWASQLiteConnection.d.ts +9 -0
- package/lib/src/worker/db/WorkerWASQLiteConnection.js +24 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/db/adapters/AsyncDatabaseConnection.ts +2 -0
- package/src/db/adapters/LockedAsyncDatabaseAdapter.ts +19 -10
- package/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.ts +8 -0
- package/src/db/adapters/wa-sqlite/WASQLiteConnection.ts +37 -0
- package/src/worker/db/SharedWASQLiteConnection.ts +127 -0
- package/src/worker/db/WASQLiteDB.worker.ts +25 -54
- package/src/worker/db/WorkerWASQLiteConnection.ts +29 -0
|
@@ -9627,7 +9627,7 @@ function requireDist () {
|
|
|
9627
9627
|
|
|
9628
9628
|
var distExports = requireDist();
|
|
9629
9629
|
|
|
9630
|
-
var version = "1.
|
|
9630
|
+
var version = "1.42.0";
|
|
9631
9631
|
var PACKAGE = {
|
|
9632
9632
|
version: version};
|
|
9633
9633
|
|
|
@@ -10375,9 +10375,11 @@ class AbstractRemote {
|
|
|
10375
10375
|
// Create a new stream splitting the response at line endings while also handling cancellations
|
|
10376
10376
|
// by closing the reader.
|
|
10377
10377
|
const reader = res.body.getReader();
|
|
10378
|
+
let readerReleased = false;
|
|
10378
10379
|
// This will close the network request and read stream
|
|
10379
10380
|
const closeReader = async () => {
|
|
10380
10381
|
try {
|
|
10382
|
+
readerReleased = true;
|
|
10381
10383
|
await reader.cancel();
|
|
10382
10384
|
}
|
|
10383
10385
|
catch (ex) {
|
|
@@ -10385,17 +10387,21 @@ class AbstractRemote {
|
|
|
10385
10387
|
}
|
|
10386
10388
|
reader.releaseLock();
|
|
10387
10389
|
};
|
|
10390
|
+
const stream = new DataStream({
|
|
10391
|
+
logger: this.logger,
|
|
10392
|
+
mapLine: mapLine
|
|
10393
|
+
});
|
|
10388
10394
|
abortSignal?.addEventListener('abort', () => {
|
|
10389
10395
|
closeReader();
|
|
10396
|
+
stream.close();
|
|
10390
10397
|
});
|
|
10391
10398
|
const decoder = this.createTextDecoder();
|
|
10392
10399
|
let buffer = '';
|
|
10393
|
-
const stream = new DataStream({
|
|
10394
|
-
logger: this.logger,
|
|
10395
|
-
mapLine: mapLine
|
|
10396
|
-
});
|
|
10397
10400
|
const l = stream.registerListener({
|
|
10398
10401
|
lowWater: async () => {
|
|
10402
|
+
if (stream.closed || abortSignal?.aborted || readerReleased) {
|
|
10403
|
+
return;
|
|
10404
|
+
}
|
|
10399
10405
|
try {
|
|
10400
10406
|
let didCompleteLine = false;
|
|
10401
10407
|
while (!didCompleteLine) {
|
|
@@ -11555,6 +11561,7 @@ class TriggerManagerImpl {
|
|
|
11555
11561
|
await hooks?.beforeCreate?.(tx);
|
|
11556
11562
|
await tx.execute(/* sql */ `
|
|
11557
11563
|
CREATE TEMP TABLE ${destination} (
|
|
11564
|
+
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
11558
11565
|
id TEXT,
|
|
11559
11566
|
operation TEXT,
|
|
11560
11567
|
timestamp TEXT,
|
|
@@ -11665,17 +11672,20 @@ class TriggerManagerImpl {
|
|
|
11665
11672
|
const callbackResult = await options.onChange({
|
|
11666
11673
|
...tx,
|
|
11667
11674
|
destinationTable: destination,
|
|
11668
|
-
withDiff: async (query, params) => {
|
|
11675
|
+
withDiff: async (query, params, options) => {
|
|
11669
11676
|
// Wrap the query to expose the destination table
|
|
11677
|
+
const operationIdSelect = options?.castOperationIdAsText
|
|
11678
|
+
? 'id, operation, CAST(operation_id AS TEXT) as operation_id, timestamp, value, previous_value'
|
|
11679
|
+
: '*';
|
|
11670
11680
|
const wrappedQuery = /* sql */ `
|
|
11671
11681
|
WITH
|
|
11672
11682
|
DIFF AS (
|
|
11673
11683
|
SELECT
|
|
11674
|
-
|
|
11684
|
+
${operationIdSelect}
|
|
11675
11685
|
FROM
|
|
11676
11686
|
${destination}
|
|
11677
11687
|
ORDER BY
|
|
11678
|
-
|
|
11688
|
+
operation_id ASC
|
|
11679
11689
|
) ${query}
|
|
11680
11690
|
`;
|
|
11681
11691
|
return tx.getAll(wrappedQuery, params);
|
|
@@ -11689,13 +11699,14 @@ class TriggerManagerImpl {
|
|
|
11689
11699
|
id,
|
|
11690
11700
|
${contextColumns.length > 0
|
|
11691
11701
|
? `${contextColumns.map((col) => `json_extract(value, '$.${col}') as ${col}`).join(', ')},`
|
|
11692
|
-
: ''}
|
|
11702
|
+
: ''} operation_id as __operation_id,
|
|
11703
|
+
operation as __operation,
|
|
11693
11704
|
timestamp as __timestamp,
|
|
11694
11705
|
previous_value as __previous_value
|
|
11695
11706
|
FROM
|
|
11696
11707
|
${destination}
|
|
11697
11708
|
ORDER BY
|
|
11698
|
-
|
|
11709
|
+
__operation_id ASC
|
|
11699
11710
|
) ${query}
|
|
11700
11711
|
`;
|
|
11701
11712
|
return tx.getAll(wrappedQuery, params);
|
|
@@ -15903,6 +15914,8 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
|
|
|
15903
15914
|
* notification loops.
|
|
15904
15915
|
*/
|
|
15905
15916
|
connectionId;
|
|
15917
|
+
_holdCounter;
|
|
15918
|
+
_holdId;
|
|
15906
15919
|
constructor(options) {
|
|
15907
15920
|
super();
|
|
15908
15921
|
this.options = options;
|
|
@@ -15912,6 +15925,15 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
|
|
|
15912
15925
|
this.connectionId = new Date().valueOf() + Math.random();
|
|
15913
15926
|
this.statementMutex = new async_mutex__WEBPACK_IMPORTED_MODULE_2__.Mutex();
|
|
15914
15927
|
this._moduleFactory = DEFAULT_MODULE_FACTORIES[this.options.vfs];
|
|
15928
|
+
this._holdCounter = 0;
|
|
15929
|
+
this._holdId = null;
|
|
15930
|
+
}
|
|
15931
|
+
/**
|
|
15932
|
+
* Gets the id for the current hold.
|
|
15933
|
+
* This can be used to check for invalid states.
|
|
15934
|
+
*/
|
|
15935
|
+
get currentHoldId() {
|
|
15936
|
+
return this._holdId;
|
|
15915
15937
|
}
|
|
15916
15938
|
get sqliteAPI() {
|
|
15917
15939
|
if (!this._sqliteAPI) {
|
|
@@ -15925,6 +15947,20 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
|
|
|
15925
15947
|
}
|
|
15926
15948
|
return this._dbP;
|
|
15927
15949
|
}
|
|
15950
|
+
async markHold() {
|
|
15951
|
+
const previousHoldId = this._holdId;
|
|
15952
|
+
this._holdId = `${++this._holdCounter}`;
|
|
15953
|
+
if (previousHoldId) {
|
|
15954
|
+
await this.iterateAsyncListeners(async (cb) => cb.holdOverwritten?.(previousHoldId));
|
|
15955
|
+
}
|
|
15956
|
+
return this._holdId;
|
|
15957
|
+
}
|
|
15958
|
+
async releaseHold(holdId) {
|
|
15959
|
+
if (holdId != this._holdId) {
|
|
15960
|
+
throw new Error(`Invalid hold state, expected ${this._holdId} but got ${holdId}`);
|
|
15961
|
+
}
|
|
15962
|
+
this._holdId = null;
|
|
15963
|
+
}
|
|
15928
15964
|
async openDB() {
|
|
15929
15965
|
this._dbP = await this.sqliteAPI.open_v2(this.options.dbFilename);
|
|
15930
15966
|
return this._dbP;
|
|
@@ -16177,6 +16213,152 @@ const getNavigatorLocks = () => {
|
|
|
16177
16213
|
};
|
|
16178
16214
|
|
|
16179
16215
|
|
|
16216
|
+
/***/ }),
|
|
16217
|
+
|
|
16218
|
+
/***/ "./lib/src/worker/db/SharedWASQLiteConnection.js":
|
|
16219
|
+
/*!*******************************************************!*\
|
|
16220
|
+
!*** ./lib/src/worker/db/SharedWASQLiteConnection.js ***!
|
|
16221
|
+
\*******************************************************/
|
|
16222
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
16223
|
+
|
|
16224
|
+
"use strict";
|
|
16225
|
+
__webpack_require__.r(__webpack_exports__);
|
|
16226
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
16227
|
+
/* harmony export */ SharedWASQLiteConnection: () => (/* binding */ SharedWASQLiteConnection)
|
|
16228
|
+
/* harmony export */ });
|
|
16229
|
+
class SharedWASQLiteConnection {
|
|
16230
|
+
options;
|
|
16231
|
+
isClosing;
|
|
16232
|
+
// Keeps track if this current hold if the shared connection has a hold
|
|
16233
|
+
activeHoldId;
|
|
16234
|
+
constructor(options) {
|
|
16235
|
+
this.options = options;
|
|
16236
|
+
// Add this client ID to the set of known clients
|
|
16237
|
+
this.clientIds.add(options.clientId);
|
|
16238
|
+
this.isClosing = false;
|
|
16239
|
+
this.activeHoldId = null;
|
|
16240
|
+
}
|
|
16241
|
+
async init() {
|
|
16242
|
+
// No-op since the connection is already initialized when it was created
|
|
16243
|
+
}
|
|
16244
|
+
async markHold() {
|
|
16245
|
+
this.activeHoldId = await this.connection.markHold();
|
|
16246
|
+
return this.activeHoldId;
|
|
16247
|
+
}
|
|
16248
|
+
async releaseHold(id) {
|
|
16249
|
+
try {
|
|
16250
|
+
await this.connection.releaseHold(id);
|
|
16251
|
+
}
|
|
16252
|
+
finally {
|
|
16253
|
+
this.activeHoldId = null;
|
|
16254
|
+
}
|
|
16255
|
+
}
|
|
16256
|
+
get logger() {
|
|
16257
|
+
return this.options.logger;
|
|
16258
|
+
}
|
|
16259
|
+
get dbEntry() {
|
|
16260
|
+
return this.options.dbMap.get(this.options.dbFilename);
|
|
16261
|
+
}
|
|
16262
|
+
get connection() {
|
|
16263
|
+
return this.dbEntry.db;
|
|
16264
|
+
}
|
|
16265
|
+
get clientIds() {
|
|
16266
|
+
return this.dbEntry.clientIds;
|
|
16267
|
+
}
|
|
16268
|
+
/**
|
|
16269
|
+
* Handles closing of a shared connection.
|
|
16270
|
+
* The connection is only closed if there are no active clients using it.
|
|
16271
|
+
*/
|
|
16272
|
+
async close() {
|
|
16273
|
+
// This prevents further statements on this connection from being executed
|
|
16274
|
+
this.isClosing = true;
|
|
16275
|
+
const { clientIds, logger } = this;
|
|
16276
|
+
const { clientId, dbFilename, dbMap } = this.options;
|
|
16277
|
+
logger.debug(`Close requested from client ${clientId} of ${[...clientIds]}`);
|
|
16278
|
+
clientIds.delete(clientId);
|
|
16279
|
+
if (this.activeHoldId) {
|
|
16280
|
+
/**
|
|
16281
|
+
* The hold hasn't been released, but we're closing now.
|
|
16282
|
+
* We can proactively cleanup and release the hold.
|
|
16283
|
+
*/
|
|
16284
|
+
await this.connection.execute('ROLLBACK').catch(() => { });
|
|
16285
|
+
await this.connection.releaseHold(this.activeHoldId).catch(() => { });
|
|
16286
|
+
}
|
|
16287
|
+
if (clientIds.size == 0) {
|
|
16288
|
+
logger.debug(`Closing connection to ${this.options}.`);
|
|
16289
|
+
const connection = this.connection;
|
|
16290
|
+
dbMap.delete(dbFilename);
|
|
16291
|
+
await connection.close();
|
|
16292
|
+
}
|
|
16293
|
+
logger.debug(`Connection to ${dbFilename} not closed yet due to active clients.`);
|
|
16294
|
+
return;
|
|
16295
|
+
}
|
|
16296
|
+
async withClosing(action) {
|
|
16297
|
+
if (this.isClosing) {
|
|
16298
|
+
throw new Error('Connection is closing');
|
|
16299
|
+
}
|
|
16300
|
+
return action();
|
|
16301
|
+
}
|
|
16302
|
+
async execute(sql, params) {
|
|
16303
|
+
return this.withClosing(() => this.connection.execute(sql, params));
|
|
16304
|
+
}
|
|
16305
|
+
async executeRaw(sql, params) {
|
|
16306
|
+
return this.withClosing(() => this.connection.executeRaw(sql, params));
|
|
16307
|
+
}
|
|
16308
|
+
executeBatch(sql, params) {
|
|
16309
|
+
return this.withClosing(() => this.connection.executeBatch(sql, params));
|
|
16310
|
+
}
|
|
16311
|
+
registerOnTableChange(callback) {
|
|
16312
|
+
return this.connection.registerOnTableChange(callback);
|
|
16313
|
+
}
|
|
16314
|
+
getConfig() {
|
|
16315
|
+
return this.connection.getConfig();
|
|
16316
|
+
}
|
|
16317
|
+
}
|
|
16318
|
+
|
|
16319
|
+
|
|
16320
|
+
/***/ }),
|
|
16321
|
+
|
|
16322
|
+
/***/ "./lib/src/worker/db/WorkerWASQLiteConnection.js":
|
|
16323
|
+
/*!*******************************************************!*\
|
|
16324
|
+
!*** ./lib/src/worker/db/WorkerWASQLiteConnection.js ***!
|
|
16325
|
+
\*******************************************************/
|
|
16326
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
16327
|
+
|
|
16328
|
+
"use strict";
|
|
16329
|
+
__webpack_require__.r(__webpack_exports__);
|
|
16330
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
16331
|
+
/* harmony export */ WorkerWASQLiteConnection: () => (/* binding */ WorkerWASQLiteConnection),
|
|
16332
|
+
/* harmony export */ proxyWASQLiteConnection: () => (/* binding */ proxyWASQLiteConnection)
|
|
16333
|
+
/* harmony export */ });
|
|
16334
|
+
/* harmony import */ var comlink__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! comlink */ "../../node_modules/comlink/dist/esm/comlink.mjs");
|
|
16335
|
+
/* harmony import */ var _db_adapters_wa_sqlite_WASQLiteConnection__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../db/adapters/wa-sqlite/WASQLiteConnection */ "./lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js");
|
|
16336
|
+
|
|
16337
|
+
|
|
16338
|
+
/**
|
|
16339
|
+
* Fully proxies a WASQLiteConnection to be used as an AsyncDatabaseConnection.
|
|
16340
|
+
*/
|
|
16341
|
+
function proxyWASQLiteConnection(connection) {
|
|
16342
|
+
return comlink__WEBPACK_IMPORTED_MODULE_1__.proxy({
|
|
16343
|
+
init: comlink__WEBPACK_IMPORTED_MODULE_1__.proxy(() => connection.init()),
|
|
16344
|
+
close: comlink__WEBPACK_IMPORTED_MODULE_1__.proxy(() => connection.close()),
|
|
16345
|
+
markHold: comlink__WEBPACK_IMPORTED_MODULE_1__.proxy(() => connection.markHold()),
|
|
16346
|
+
releaseHold: comlink__WEBPACK_IMPORTED_MODULE_1__.proxy((holdId) => connection.releaseHold(holdId)),
|
|
16347
|
+
execute: comlink__WEBPACK_IMPORTED_MODULE_1__.proxy((sql, params) => connection.execute(sql, params)),
|
|
16348
|
+
executeRaw: comlink__WEBPACK_IMPORTED_MODULE_1__.proxy((sql, params) => connection.executeRaw(sql, params)),
|
|
16349
|
+
executeBatch: comlink__WEBPACK_IMPORTED_MODULE_1__.proxy((sql, params) => connection.executeBatch(sql, params)),
|
|
16350
|
+
registerOnTableChange: comlink__WEBPACK_IMPORTED_MODULE_1__.proxy((callback) => connection.registerOnTableChange(callback)),
|
|
16351
|
+
getConfig: comlink__WEBPACK_IMPORTED_MODULE_1__.proxy(() => connection.getConfig())
|
|
16352
|
+
});
|
|
16353
|
+
}
|
|
16354
|
+
class WorkerWASQLiteConnection extends _db_adapters_wa_sqlite_WASQLiteConnection__WEBPACK_IMPORTED_MODULE_0__.WASqliteConnection {
|
|
16355
|
+
async registerOnTableChange(callback) {
|
|
16356
|
+
// Proxy the callback remove function
|
|
16357
|
+
return comlink__WEBPACK_IMPORTED_MODULE_1__.proxy(await super.registerOnTableChange(callback));
|
|
16358
|
+
}
|
|
16359
|
+
}
|
|
16360
|
+
|
|
16361
|
+
|
|
16180
16362
|
/***/ })
|
|
16181
16363
|
|
|
16182
16364
|
/******/ });
|
|
@@ -16346,9 +16528,10 @@ var __webpack_exports__ = {};
|
|
|
16346
16528
|
__webpack_require__.r(__webpack_exports__);
|
|
16347
16529
|
/* harmony import */ var _journeyapps_wa_sqlite__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @journeyapps/wa-sqlite */ "../../node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js");
|
|
16348
16530
|
/* harmony import */ var _powersync_common__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @powersync/common */ "../common/dist/bundle.mjs");
|
|
16349
|
-
/* harmony import */ var
|
|
16350
|
-
/* harmony import */ var
|
|
16351
|
-
/* harmony import */ var
|
|
16531
|
+
/* harmony import */ var comlink__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! comlink */ "../../node_modules/comlink/dist/esm/comlink.mjs");
|
|
16532
|
+
/* harmony import */ var _shared_navigator__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../shared/navigator */ "./lib/src/shared/navigator.js");
|
|
16533
|
+
/* harmony import */ var _SharedWASQLiteConnection__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./SharedWASQLiteConnection */ "./lib/src/worker/db/SharedWASQLiteConnection.js");
|
|
16534
|
+
/* harmony import */ var _WorkerWASQLiteConnection__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./WorkerWASQLiteConnection */ "./lib/src/worker/db/WorkerWASQLiteConnection.js");
|
|
16352
16535
|
/**
|
|
16353
16536
|
* Supports both shared and dedicated workers, based on how the worker is constructed (new SharedWorker vs new Worker()).
|
|
16354
16537
|
*/
|
|
@@ -16357,64 +16540,47 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
16357
16540
|
|
|
16358
16541
|
|
|
16359
16542
|
|
|
16543
|
+
|
|
16360
16544
|
const baseLogger = (0,_powersync_common__WEBPACK_IMPORTED_MODULE_1__.createBaseLogger)();
|
|
16361
16545
|
baseLogger.useDefaults();
|
|
16362
16546
|
const logger = (0,_powersync_common__WEBPACK_IMPORTED_MODULE_1__.createLogger)('db-worker');
|
|
16363
16547
|
const DBMap = new Map();
|
|
16364
16548
|
const OPEN_DB_LOCK = 'open-wasqlite-db';
|
|
16365
16549
|
let nextClientId = 1;
|
|
16366
|
-
const openWorkerConnection = async (options) => {
|
|
16367
|
-
const connection = new _db_adapters_wa_sqlite_WASQLiteConnection__WEBPACK_IMPORTED_MODULE_2__.WASqliteConnection(options);
|
|
16368
|
-
return {
|
|
16369
|
-
init: comlink__WEBPACK_IMPORTED_MODULE_4__.proxy(() => connection.init()),
|
|
16370
|
-
getConfig: comlink__WEBPACK_IMPORTED_MODULE_4__.proxy(() => connection.getConfig()),
|
|
16371
|
-
close: comlink__WEBPACK_IMPORTED_MODULE_4__.proxy(() => connection.close()),
|
|
16372
|
-
execute: comlink__WEBPACK_IMPORTED_MODULE_4__.proxy(async (sql, params) => connection.execute(sql, params)),
|
|
16373
|
-
executeRaw: comlink__WEBPACK_IMPORTED_MODULE_4__.proxy(async (sql, params) => connection.executeRaw(sql, params)),
|
|
16374
|
-
executeBatch: comlink__WEBPACK_IMPORTED_MODULE_4__.proxy(async (sql, params) => connection.executeBatch(sql, params)),
|
|
16375
|
-
registerOnTableChange: comlink__WEBPACK_IMPORTED_MODULE_4__.proxy(async (callback) => {
|
|
16376
|
-
// Proxy the callback remove function
|
|
16377
|
-
return comlink__WEBPACK_IMPORTED_MODULE_4__.proxy(await connection.registerOnTableChange(callback));
|
|
16378
|
-
})
|
|
16379
|
-
};
|
|
16380
|
-
};
|
|
16381
16550
|
const openDBShared = async (options) => {
|
|
16382
16551
|
// Prevent multiple simultaneous opens from causing race conditions
|
|
16383
|
-
return (0,
|
|
16552
|
+
return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_2__.getNavigatorLocks)().request(OPEN_DB_LOCK, async () => {
|
|
16384
16553
|
const clientId = nextClientId++;
|
|
16385
16554
|
const { dbFilename, logLevel } = options;
|
|
16386
16555
|
logger.setLevel(logLevel);
|
|
16387
16556
|
if (!DBMap.has(dbFilename)) {
|
|
16388
16557
|
const clientIds = new Set();
|
|
16389
|
-
|
|
16558
|
+
// This format returns proxy objects for function callbacks
|
|
16559
|
+
const connection = new _WorkerWASQLiteConnection__WEBPACK_IMPORTED_MODULE_4__.WorkerWASQLiteConnection(options);
|
|
16390
16560
|
await connection.init();
|
|
16561
|
+
connection.registerListener({
|
|
16562
|
+
holdOverwritten: async () => {
|
|
16563
|
+
/**
|
|
16564
|
+
* The previous hold has been overwritten, without being released.
|
|
16565
|
+
* we need to cleanup any resources associated with it.
|
|
16566
|
+
* We can perform a rollback to release any potential transactions that were started.
|
|
16567
|
+
*/
|
|
16568
|
+
await connection.execute('ROLLBACK').catch(() => { });
|
|
16569
|
+
}
|
|
16570
|
+
});
|
|
16391
16571
|
DBMap.set(dbFilename, {
|
|
16392
16572
|
clientIds,
|
|
16393
16573
|
db: connection
|
|
16394
16574
|
});
|
|
16395
16575
|
}
|
|
16396
|
-
|
|
16397
|
-
|
|
16398
|
-
|
|
16399
|
-
|
|
16400
|
-
|
|
16401
|
-
|
|
16402
|
-
|
|
16403
|
-
|
|
16404
|
-
close: comlink__WEBPACK_IMPORTED_MODULE_4__.proxy(async () => {
|
|
16405
|
-
const { clientIds } = dbEntry;
|
|
16406
|
-
logger.debug(`Close requested from client ${clientId} of ${[...clientIds]}`);
|
|
16407
|
-
clientIds.delete(clientId);
|
|
16408
|
-
if (clientIds.size == 0) {
|
|
16409
|
-
logger.debug(`Closing connection to ${dbFilename}.`);
|
|
16410
|
-
DBMap.delete(dbFilename);
|
|
16411
|
-
return db.close?.();
|
|
16412
|
-
}
|
|
16413
|
-
logger.debug(`Connection to ${dbFilename} not closed yet due to active clients.`);
|
|
16414
|
-
return;
|
|
16415
|
-
})
|
|
16416
|
-
};
|
|
16417
|
-
return comlink__WEBPACK_IMPORTED_MODULE_4__.proxy(wrappedConnection);
|
|
16576
|
+
// Associates this clientId with the shared connection entry
|
|
16577
|
+
const sharedConnection = new _SharedWASQLiteConnection__WEBPACK_IMPORTED_MODULE_3__.SharedWASQLiteConnection({
|
|
16578
|
+
dbMap: DBMap,
|
|
16579
|
+
dbFilename,
|
|
16580
|
+
clientId,
|
|
16581
|
+
logger
|
|
16582
|
+
});
|
|
16583
|
+
return (0,_WorkerWASQLiteConnection__WEBPACK_IMPORTED_MODULE_4__.proxyWASQLiteConnection)(sharedConnection);
|
|
16418
16584
|
});
|
|
16419
16585
|
};
|
|
16420
16586
|
// Check if we're in a SharedWorker context
|
|
@@ -16422,12 +16588,12 @@ if (typeof SharedWorkerGlobalScope !== 'undefined') {
|
|
|
16422
16588
|
const _self = self;
|
|
16423
16589
|
_self.onconnect = function (event) {
|
|
16424
16590
|
const port = event.ports[0];
|
|
16425
|
-
|
|
16591
|
+
comlink__WEBPACK_IMPORTED_MODULE_5__.expose(openDBShared, port);
|
|
16426
16592
|
};
|
|
16427
16593
|
}
|
|
16428
16594
|
else {
|
|
16429
16595
|
// A dedicated worker can be shared externally
|
|
16430
|
-
|
|
16596
|
+
comlink__WEBPACK_IMPORTED_MODULE_5__.expose(openDBShared);
|
|
16431
16597
|
}
|
|
16432
16598
|
addEventListener('unload', () => {
|
|
16433
16599
|
Array.from(DBMap.values()).forEach(async (dbConnection) => {
|