@powersync/web 1.38.6 → 1.39.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/dist/index.umd.js +259 -51
- package/dist/index.umd.js.map +1 -1
- package/dist/worker/SharedSyncImplementation.umd.js +11 -3
- package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
- package/dist/worker/WASQLiteDB.umd.js +78 -54
- package/dist/worker/WASQLiteDB.umd.js.map +1 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js +1400 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js.map +1 -0
- package/lib/package.json +2 -2
- package/lib/src/db/adapters/wa-sqlite/RawSqliteConnection.d.ts +0 -1
- package/lib/src/db/adapters/wa-sqlite/RawSqliteConnection.js +4 -9
- package/lib/src/db/adapters/wa-sqlite/RawSqliteConnection.js.map +1 -1
- package/lib/src/db/adapters/wa-sqlite/vfs.d.ts +20 -30
- package/lib/src/db/adapters/wa-sqlite/vfs.js +57 -39
- package/lib/src/db/adapters/wa-sqlite/vfs.js.map +1 -1
- package/lib/src/worker/db/MultiDatabaseServer.js +5 -3
- package/lib/src/worker/db/MultiDatabaseServer.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/db/adapters/wa-sqlite/RawSqliteConnection.ts +5 -11
- package/src/db/adapters/wa-sqlite/vfs.ts +67 -54
- package/src/worker/db/MultiDatabaseServer.ts +5 -3
|
@@ -2433,10 +2433,8 @@ class RawSqliteConnection {
|
|
|
2433
2433
|
* The `sqlite3*` connection pointer.
|
|
2434
2434
|
*/
|
|
2435
2435
|
db = 0;
|
|
2436
|
-
_moduleFactory;
|
|
2437
2436
|
constructor(options) {
|
|
2438
2437
|
this.options = options;
|
|
2439
|
-
this._moduleFactory = _vfs_js__WEBPACK_IMPORTED_MODULE_1__.DEFAULT_MODULE_FACTORIES[this.options.vfs];
|
|
2440
2438
|
}
|
|
2441
2439
|
get isOpen() {
|
|
2442
2440
|
return this.db != 0;
|
|
@@ -2446,17 +2444,14 @@ class RawSqliteConnection {
|
|
|
2446
2444
|
this.db = await api.open_v2(this.options.dbFilename, this.options.isReadOnly ? 1 /* SQLITE_OPEN_READONLY */ : 6 /* SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE */);
|
|
2447
2445
|
await this.executeRaw(`PRAGMA temp_store = ${this.options.temporaryStorage};`);
|
|
2448
2446
|
if (this.options.encryptionKey) {
|
|
2449
|
-
const escapedKey = this.options.encryptionKey.
|
|
2450
|
-
await this.executeRaw(`PRAGMA key = '${escapedKey}'
|
|
2447
|
+
const escapedKey = this.options.encryptionKey.replaceAll("'", "''");
|
|
2448
|
+
await this.executeRaw(`PRAGMA key = '${escapedKey}';`);
|
|
2451
2449
|
}
|
|
2452
2450
|
await this.executeRaw(`PRAGMA cache_size = -${this.options.cacheSizeKb};`);
|
|
2453
2451
|
await this.executeRaw(`SELECT powersync_update_hooks('install');`);
|
|
2454
2452
|
}
|
|
2455
2453
|
async openSQLiteAPI() {
|
|
2456
|
-
const { module, vfs } = await this.
|
|
2457
|
-
dbFileName: this.options.dbFilename,
|
|
2458
|
-
encryptionKey: this.options.encryptionKey
|
|
2459
|
-
});
|
|
2454
|
+
const { module, vfs } = await (0,_vfs_js__WEBPACK_IMPORTED_MODULE_1__.loadModuleAndVfs)(this.options);
|
|
2460
2455
|
const sqlite3 = (0,_journeyapps_wa_sqlite__WEBPACK_IMPORTED_MODULE_0__.Factory)(module);
|
|
2461
2456
|
sqlite3.vfs_register(vfs, true);
|
|
2462
2457
|
/**
|
|
@@ -2577,8 +2572,8 @@ class RawSqliteConnection {
|
|
|
2577
2572
|
|
|
2578
2573
|
__webpack_require__.r(__webpack_exports__);
|
|
2579
2574
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
2580
|
-
/* harmony export */ DEFAULT_MODULE_FACTORIES: () => (/* binding */ DEFAULT_MODULE_FACTORIES),
|
|
2581
2575
|
/* harmony export */ WASQLiteVFS: () => (/* binding */ WASQLiteVFS),
|
|
2576
|
+
/* harmony export */ loadModuleAndVfs: () => (/* binding */ loadModuleAndVfs),
|
|
2582
2577
|
/* harmony export */ vfsRequiresDedicatedWorkers: () => (/* binding */ vfsRequiresDedicatedWorkers)
|
|
2583
2578
|
/* harmony export */ });
|
|
2584
2579
|
/**
|
|
@@ -2590,9 +2585,26 @@ var WASQLiteVFS;
|
|
|
2590
2585
|
WASQLiteVFS["OPFSCoopSyncVFS"] = "OPFSCoopSyncVFS";
|
|
2591
2586
|
WASQLiteVFS["AccessHandlePoolVFS"] = "AccessHandlePoolVFS";
|
|
2592
2587
|
WASQLiteVFS["OPFSWriteAheadVFS"] = "OPFSWriteAheadVFS";
|
|
2588
|
+
/**
|
|
2589
|
+
* A virtual file system storing data in-memory only, without persistence.
|
|
2590
|
+
*
|
|
2591
|
+
* This file system can be used in three configurations:
|
|
2592
|
+
*
|
|
2593
|
+
* 1. In shared workers (the default when available): All tabs share the same in-memory database, which is cleared
|
|
2594
|
+
* once the last tab is closed.
|
|
2595
|
+
* 2. In dedicated workers (used when `enableMultiTabs` is disabled). Each tab has its own in-memory database cleared
|
|
2596
|
+
* when the tab is closed. Queries are offloaded to a dedicated worker.
|
|
2597
|
+
* 3. In the context of the tab itself (used when both `enableMultiTabs` and `useWebWorker` are disabled). The per-tab
|
|
2598
|
+
* database is hosted in the tab itself, and queries run synchronously. This is _a lot_ faster than any other
|
|
2599
|
+
* single-threadedVFS, but can block JavaScript for computationally-intensive queries.
|
|
2600
|
+
*
|
|
2601
|
+
* This VFS primarily intended for development, but it also useful for online-first deployments not syncing large
|
|
2602
|
+
* amounts of data, as it is quicker to start up.
|
|
2603
|
+
*/
|
|
2604
|
+
WASQLiteVFS["InMemoryVfs"] = "InMemoryVFS";
|
|
2593
2605
|
})(WASQLiteVFS || (WASQLiteVFS = {}));
|
|
2594
2606
|
function vfsRequiresDedicatedWorkers(vfs) {
|
|
2595
|
-
return vfs != WASQLiteVFS.IDBBatchAtomicVFS;
|
|
2607
|
+
return vfs != WASQLiteVFS.IDBBatchAtomicVFS && vfs != WASQLiteVFS.InMemoryVfs;
|
|
2596
2608
|
}
|
|
2597
2609
|
async function asyncModuleFactory(encryptionKey) {
|
|
2598
2610
|
if (encryptionKey) {
|
|
@@ -2617,46 +2629,47 @@ async function syncModuleFactory(encryptionKey) {
|
|
|
2617
2629
|
/**
|
|
2618
2630
|
* @internal
|
|
2619
2631
|
*/
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2632
|
+
async function loadModuleAndVfs({ vfs, dbFilename, encryptionKey }) {
|
|
2633
|
+
let moduleFactory = syncModuleFactory;
|
|
2634
|
+
let resolveVfs;
|
|
2635
|
+
switch (vfs) {
|
|
2636
|
+
case WASQLiteVFS.IDBBatchAtomicVFS: {
|
|
2637
|
+
moduleFactory = asyncModuleFactory;
|
|
2638
|
+
const { IDBBatchAtomicVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js"));
|
|
2639
|
+
resolveVfs = (module) => {
|
|
2640
|
+
// @ts-expect-error The types for this static method are missing upstream
|
|
2641
|
+
return IDBBatchAtomicVFS.create(dbFilename, module, { lockPolicy: 'exclusive' });
|
|
2642
|
+
};
|
|
2643
|
+
break;
|
|
2644
|
+
}
|
|
2645
|
+
case WASQLiteVFS.AccessHandlePoolVFS: {
|
|
2646
|
+
// @ts-expect-error The types for this import are missing upstream
|
|
2647
|
+
const { AccessHandlePoolVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js"));
|
|
2648
|
+
resolveVfs = (module) => AccessHandlePoolVFS.create(dbFilename, module);
|
|
2649
|
+
break;
|
|
2650
|
+
}
|
|
2651
|
+
case WASQLiteVFS.OPFSCoopSyncVFS: {
|
|
2652
|
+
// @ts-expect-error The types for this import are missing upstream
|
|
2653
|
+
const { OPFSCoopSyncVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js"));
|
|
2654
|
+
resolveVfs = (module) => OPFSCoopSyncVFS.create(dbFilename, module);
|
|
2655
|
+
break;
|
|
2656
|
+
}
|
|
2657
|
+
case WASQLiteVFS.OPFSWriteAheadVFS: {
|
|
2658
|
+
// @ts-expect-error The types for this import are missing upstream
|
|
2659
|
+
const { OPFSWriteAheadVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/OPFSWriteAheadVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/examples/OPFSWriteAheadVFS.js"));
|
|
2660
|
+
resolveVfs = (module) => OPFSWriteAheadVFS.create(dbFilename, module, {});
|
|
2661
|
+
break;
|
|
2662
|
+
}
|
|
2663
|
+
case WASQLiteVFS.InMemoryVfs: {
|
|
2664
|
+
const { MemoryVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/MemoryVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/examples/MemoryVFS.js"));
|
|
2626
2665
|
// @ts-expect-error The types for this static method are missing upstream
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
[WASQLiteVFS.AccessHandlePoolVFS]: async (options) => {
|
|
2631
|
-
const module = await syncModuleFactory(options.encryptionKey);
|
|
2632
|
-
// @ts-expect-error The types for this static method are missing upstream
|
|
2633
|
-
const { AccessHandlePoolVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js"));
|
|
2634
|
-
return {
|
|
2635
|
-
module,
|
|
2636
|
-
vfs: await AccessHandlePoolVFS.create(options.dbFileName, module)
|
|
2637
|
-
};
|
|
2638
|
-
},
|
|
2639
|
-
[WASQLiteVFS.OPFSCoopSyncVFS]: async (options) => {
|
|
2640
|
-
const module = await syncModuleFactory(options.encryptionKey);
|
|
2641
|
-
// @ts-expect-error The types for this static method are missing upstream
|
|
2642
|
-
const { OPFSCoopSyncVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js"));
|
|
2643
|
-
const vfs = await OPFSCoopSyncVFS.create(options.dbFileName, module);
|
|
2644
|
-
return {
|
|
2645
|
-
module,
|
|
2646
|
-
vfs
|
|
2647
|
-
};
|
|
2648
|
-
},
|
|
2649
|
-
[WASQLiteVFS.OPFSWriteAheadVFS]: async (options) => {
|
|
2650
|
-
const module = await syncModuleFactory(options.encryptionKey);
|
|
2651
|
-
// @ts-expect-error The types for this static method are missing upstream
|
|
2652
|
-
const { OPFSWriteAheadVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/OPFSWriteAheadVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/examples/OPFSWriteAheadVFS.js"));
|
|
2653
|
-
const vfs = await OPFSWriteAheadVFS.create(options.dbFileName, module, {});
|
|
2654
|
-
return {
|
|
2655
|
-
module,
|
|
2656
|
-
vfs
|
|
2657
|
-
};
|
|
2666
|
+
resolveVfs = (module) => MemoryVFS.create(dbFilename, module);
|
|
2667
|
+
break;
|
|
2668
|
+
}
|
|
2658
2669
|
}
|
|
2659
|
-
|
|
2670
|
+
const module = await moduleFactory(encryptionKey);
|
|
2671
|
+
return { module, vfs: await resolveVfs(module) };
|
|
2672
|
+
}
|
|
2660
2673
|
|
|
2661
2674
|
|
|
2662
2675
|
/***/ },
|
|
@@ -2697,6 +2710,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2697
2710
|
/* harmony import */ var _shared_navigator_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../shared/navigator.js */ "./lib/src/shared/navigator.js");
|
|
2698
2711
|
/* harmony import */ var _db_adapters_wa_sqlite_RawSqliteConnection_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../db/adapters/wa-sqlite/RawSqliteConnection.js */ "./lib/src/db/adapters/wa-sqlite/RawSqliteConnection.js");
|
|
2699
2712
|
/* harmony import */ var _db_adapters_wa_sqlite_ConcurrentConnection_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../db/adapters/wa-sqlite/ConcurrentConnection.js */ "./lib/src/db/adapters/wa-sqlite/ConcurrentConnection.js");
|
|
2713
|
+
/* harmony import */ var _db_adapters_wa_sqlite_vfs_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../db/adapters/wa-sqlite/vfs.js */ "./lib/src/db/adapters/wa-sqlite/vfs.js");
|
|
2714
|
+
|
|
2700
2715
|
|
|
2701
2716
|
|
|
2702
2717
|
|
|
@@ -2745,13 +2760,14 @@ class MultiDatabaseServer {
|
|
|
2745
2760
|
}
|
|
2746
2761
|
async databaseOpenAttempt(options) {
|
|
2747
2762
|
return (0,_shared_navigator_js__WEBPACK_IMPORTED_MODULE_2__.getNavigatorLocks)().request(OPEN_DB_LOCK, async () => {
|
|
2748
|
-
const { dbFilename } = options;
|
|
2763
|
+
const { dbFilename, isReadOnly, vfs } = options;
|
|
2749
2764
|
let server = this.activeDatabases.get(dbFilename);
|
|
2750
2765
|
if (server == null) {
|
|
2751
2766
|
// We don't need navigator locks for shared workers because all queries run in this shared worker exclusively.
|
|
2752
2767
|
// For read-only connections, we use a VFS that supports concurrent reads (so a single lock on the connection is
|
|
2753
|
-
// fine).
|
|
2754
|
-
|
|
2768
|
+
// fine). In-memory databases either run in a shared worker or aren't shared across tabs at all, so the internal
|
|
2769
|
+
// lock is enough.
|
|
2770
|
+
const needsNavigatorLocks = !(isSharedWorker || isReadOnly || vfs == _db_adapters_wa_sqlite_vfs_js__WEBPACK_IMPORTED_MODULE_5__.WASQLiteVFS.InMemoryVfs);
|
|
2755
2771
|
const connection = new _db_adapters_wa_sqlite_RawSqliteConnection_js__WEBPACK_IMPORTED_MODULE_3__.RawSqliteConnection(options);
|
|
2756
2772
|
const withSafeConcurrency = new _db_adapters_wa_sqlite_ConcurrentConnection_js__WEBPACK_IMPORTED_MODULE_4__.ConcurrentSqliteConnection(connection, needsNavigatorLocks);
|
|
2757
2773
|
// Initializing the RawSqliteConnection will run some pragmas that might write to the database file, so we want
|
|
@@ -5002,7 +5018,7 @@ class SyncStatus {
|
|
|
5002
5018
|
});
|
|
5003
5019
|
}
|
|
5004
5020
|
/**
|
|
5005
|
-
* All sync streams currently being tracked in
|
|
5021
|
+
* All sync streams currently being tracked in the database.
|
|
5006
5022
|
*
|
|
5007
5023
|
* This returns null when the database is currently being opened and we don't have reliable information about all
|
|
5008
5024
|
* included streams yet.
|
|
@@ -13867,7 +13883,7 @@ function requireDist () {
|
|
|
13867
13883
|
|
|
13868
13884
|
var distExports = requireDist();
|
|
13869
13885
|
|
|
13870
|
-
var version = "1.57.
|
|
13886
|
+
var version = "1.57.2";
|
|
13871
13887
|
var PACKAGE = {
|
|
13872
13888
|
version: version};
|
|
13873
13889
|
|
|
@@ -14481,6 +14497,9 @@ class AbstractRemote {
|
|
|
14481
14497
|
if (!res.ok || !res.body) {
|
|
14482
14498
|
const text = await res.text();
|
|
14483
14499
|
this.logger.error(`Could not POST streaming to ${path} - ${res.status} - ${res.statusText}: ${text}`);
|
|
14500
|
+
if (res.status === 401) {
|
|
14501
|
+
this.invalidateCredentials();
|
|
14502
|
+
}
|
|
14484
14503
|
const error = new Error(`HTTP ${res.statusText}: ${text}`);
|
|
14485
14504
|
error.status = res.status;
|
|
14486
14505
|
throw error;
|
|
@@ -15618,7 +15637,12 @@ class TriggerManagerImpl {
|
|
|
15618
15637
|
// destination table consistent.
|
|
15619
15638
|
await this.db.writeTransaction(async (tx) => {
|
|
15620
15639
|
const callbackResult = await options.onChange({
|
|
15621
|
-
|
|
15640
|
+
execute: (query, params) => tx.execute(query, params),
|
|
15641
|
+
executeBatch: (query, params) => tx.executeBatch(query, params),
|
|
15642
|
+
executeRaw: (query, params) => tx.executeRaw(query, params),
|
|
15643
|
+
get: (query, params) => tx.get(query, params),
|
|
15644
|
+
getAll: (query, params) => tx.getAll(query, params),
|
|
15645
|
+
getOptional: (query, params) => tx.getOptional(query, params),
|
|
15622
15646
|
destinationTable: destination,
|
|
15623
15647
|
withDiff: async (query, params, options) => {
|
|
15624
15648
|
// Wrap the query to expose the destination table
|