@powersync/web 1.35.0 → 1.36.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/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapp-89f0ba.index.umd.js +9 -6
- package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapp-89f0ba.index.umd.js.map +1 -1
- package/dist/index.umd.js +9 -6
- package/dist/index.umd.js.map +1 -1
- package/dist/worker/SharedSyncImplementation.umd.js +157 -14
- package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
- package/dist/worker/WASQLiteDB.umd.js +148 -8
- package/dist/worker/WASQLiteDB.umd.js.map +1 -1
- package/lib/package.json +2 -2
- package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.js +9 -6
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/db/adapters/LockedAsyncDatabaseAdapter.ts +14 -15
|
@@ -3015,6 +3015,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
3015
3015
|
/* harmony export */ CrudBatch: () => (/* binding */ CrudBatch),
|
|
3016
3016
|
/* harmony export */ CrudEntry: () => (/* binding */ CrudEntry),
|
|
3017
3017
|
/* harmony export */ CrudTransaction: () => (/* binding */ CrudTransaction),
|
|
3018
|
+
/* harmony export */ DBAdapterDefaultMixin: () => (/* binding */ DBAdapterDefaultMixin),
|
|
3019
|
+
/* harmony export */ DBGetUtilsDefaultMixin: () => (/* binding */ DBGetUtilsDefaultMixin),
|
|
3018
3020
|
/* harmony export */ DEFAULT_CRUD_BATCH_LIMIT: () => (/* binding */ DEFAULT_CRUD_BATCH_LIMIT),
|
|
3019
3021
|
/* harmony export */ DEFAULT_CRUD_UPLOAD_THROTTLE_MS: () => (/* binding */ DEFAULT_CRUD_UPLOAD_THROTTLE_MS),
|
|
3020
3022
|
/* harmony export */ DEFAULT_INDEX_COLUMN_OPTIONS: () => (/* binding */ DEFAULT_INDEX_COLUMN_OPTIONS),
|
|
@@ -4781,6 +4783,49 @@ var Logger = /*@__PURE__*/getDefaultExportFromCjs(loggerExports);
|
|
|
4781
4783
|
* Set of generic interfaces to allow PowerSync compatibility with
|
|
4782
4784
|
* different SQLite DB implementations.
|
|
4783
4785
|
*/
|
|
4786
|
+
/**
|
|
4787
|
+
* Implements {@link DBGetUtils} on a {@link SqlRunner}.
|
|
4788
|
+
*/
|
|
4789
|
+
function DBGetUtilsDefaultMixin(Base) {
|
|
4790
|
+
return class extends Base {
|
|
4791
|
+
async getAll(sql, parameters) {
|
|
4792
|
+
const res = await this.execute(sql, parameters);
|
|
4793
|
+
return res.rows?._array ?? [];
|
|
4794
|
+
}
|
|
4795
|
+
async getOptional(sql, parameters) {
|
|
4796
|
+
const res = await this.execute(sql, parameters);
|
|
4797
|
+
return res.rows?.item(0) ?? null;
|
|
4798
|
+
}
|
|
4799
|
+
async get(sql, parameters) {
|
|
4800
|
+
const res = await this.execute(sql, parameters);
|
|
4801
|
+
const first = res.rows?.item(0);
|
|
4802
|
+
if (!first) {
|
|
4803
|
+
throw new Error('Result set is empty');
|
|
4804
|
+
}
|
|
4805
|
+
return first;
|
|
4806
|
+
}
|
|
4807
|
+
async executeBatch(query, params = []) {
|
|
4808
|
+
// If this context can run batch statements natively, use that.
|
|
4809
|
+
// @ts-ignore
|
|
4810
|
+
if (super.executeBatch) {
|
|
4811
|
+
// @ts-ignore
|
|
4812
|
+
return super.executeBatch(query, params);
|
|
4813
|
+
}
|
|
4814
|
+
// Emulate executeBatch by running statements individually.
|
|
4815
|
+
let lastInsertId;
|
|
4816
|
+
let rowsAffected = 0;
|
|
4817
|
+
for (const set of params) {
|
|
4818
|
+
const result = await this.execute(query, set);
|
|
4819
|
+
lastInsertId = result.insertId;
|
|
4820
|
+
rowsAffected += result.rowsAffected;
|
|
4821
|
+
}
|
|
4822
|
+
return {
|
|
4823
|
+
rowsAffected,
|
|
4824
|
+
insertId: lastInsertId
|
|
4825
|
+
};
|
|
4826
|
+
}
|
|
4827
|
+
};
|
|
4828
|
+
}
|
|
4784
4829
|
/**
|
|
4785
4830
|
* Update table operation numbers from SQLite
|
|
4786
4831
|
*/
|
|
@@ -4790,6 +4835,89 @@ var RowUpdateType;
|
|
|
4790
4835
|
RowUpdateType[RowUpdateType["SQLITE_DELETE"] = 9] = "SQLITE_DELETE";
|
|
4791
4836
|
RowUpdateType[RowUpdateType["SQLITE_UPDATE"] = 23] = "SQLITE_UPDATE";
|
|
4792
4837
|
})(RowUpdateType || (RowUpdateType = {}));
|
|
4838
|
+
/**
|
|
4839
|
+
* A mixin to implement {@link DBAdapter} by delegating to {@link ConnectionPool.readLock} and
|
|
4840
|
+
* {@link ConnectionPool.writeLock}.
|
|
4841
|
+
*/
|
|
4842
|
+
function DBAdapterDefaultMixin(Base) {
|
|
4843
|
+
return class extends Base {
|
|
4844
|
+
readTransaction(fn, options) {
|
|
4845
|
+
return this.readLock((ctx) => TransactionImplementation.runWith(ctx, fn), options);
|
|
4846
|
+
}
|
|
4847
|
+
writeTransaction(fn, options) {
|
|
4848
|
+
return this.writeLock((ctx) => TransactionImplementation.runWith(ctx, fn), options);
|
|
4849
|
+
}
|
|
4850
|
+
getAll(sql, parameters) {
|
|
4851
|
+
return this.readLock((ctx) => ctx.getAll(sql, parameters));
|
|
4852
|
+
}
|
|
4853
|
+
getOptional(sql, parameters) {
|
|
4854
|
+
return this.readLock((ctx) => ctx.getOptional(sql, parameters));
|
|
4855
|
+
}
|
|
4856
|
+
get(sql, parameters) {
|
|
4857
|
+
return this.readLock((ctx) => ctx.get(sql, parameters));
|
|
4858
|
+
}
|
|
4859
|
+
execute(query, params) {
|
|
4860
|
+
return this.writeLock((ctx) => ctx.execute(query, params));
|
|
4861
|
+
}
|
|
4862
|
+
executeRaw(query, params) {
|
|
4863
|
+
return this.writeLock((ctx) => ctx.executeRaw(query, params));
|
|
4864
|
+
}
|
|
4865
|
+
executeBatch(query, params) {
|
|
4866
|
+
return this.writeTransaction((tx) => tx.executeBatch(query, params));
|
|
4867
|
+
}
|
|
4868
|
+
};
|
|
4869
|
+
}
|
|
4870
|
+
class BaseTransaction {
|
|
4871
|
+
inner;
|
|
4872
|
+
finalized = false;
|
|
4873
|
+
constructor(inner) {
|
|
4874
|
+
this.inner = inner;
|
|
4875
|
+
}
|
|
4876
|
+
async commit() {
|
|
4877
|
+
if (this.finalized) {
|
|
4878
|
+
return { rowsAffected: 0 };
|
|
4879
|
+
}
|
|
4880
|
+
this.finalized = true;
|
|
4881
|
+
return this.inner.execute('COMMIT');
|
|
4882
|
+
}
|
|
4883
|
+
async rollback() {
|
|
4884
|
+
if (this.finalized) {
|
|
4885
|
+
return { rowsAffected: 0 };
|
|
4886
|
+
}
|
|
4887
|
+
this.finalized = true;
|
|
4888
|
+
return this.inner.execute('ROLLBACK');
|
|
4889
|
+
}
|
|
4890
|
+
execute(query, params) {
|
|
4891
|
+
return this.inner.execute(query, params);
|
|
4892
|
+
}
|
|
4893
|
+
executeRaw(query, params) {
|
|
4894
|
+
return this.inner.executeRaw(query, params);
|
|
4895
|
+
}
|
|
4896
|
+
executeBatch(query, params) {
|
|
4897
|
+
return this.inner.executeBatch(query, params);
|
|
4898
|
+
}
|
|
4899
|
+
}
|
|
4900
|
+
class TransactionImplementation extends DBGetUtilsDefaultMixin(BaseTransaction) {
|
|
4901
|
+
static async runWith(ctx, fn) {
|
|
4902
|
+
let tx = new TransactionImplementation(ctx);
|
|
4903
|
+
try {
|
|
4904
|
+
await ctx.execute('BEGIN IMMEDIATE');
|
|
4905
|
+
const result = await fn(tx);
|
|
4906
|
+
await tx.commit();
|
|
4907
|
+
return result;
|
|
4908
|
+
}
|
|
4909
|
+
catch (ex) {
|
|
4910
|
+
try {
|
|
4911
|
+
await tx.rollback();
|
|
4912
|
+
}
|
|
4913
|
+
catch (ex2) {
|
|
4914
|
+
// In rare cases, a rollback may fail.
|
|
4915
|
+
// Safe to ignore.
|
|
4916
|
+
}
|
|
4917
|
+
throw ex;
|
|
4918
|
+
}
|
|
4919
|
+
}
|
|
4920
|
+
}
|
|
4793
4921
|
function isBatchedUpdateNotification(update) {
|
|
4794
4922
|
return 'tables' in update;
|
|
4795
4923
|
}
|
|
@@ -13555,7 +13683,7 @@ function requireDist () {
|
|
|
13555
13683
|
|
|
13556
13684
|
var distExports = requireDist();
|
|
13557
13685
|
|
|
13558
|
-
var version = "1.
|
|
13686
|
+
var version = "1.49.0";
|
|
13559
13687
|
var PACKAGE = {
|
|
13560
13688
|
version: version};
|
|
13561
13689
|
|
|
@@ -15588,7 +15716,7 @@ class TriggerManagerImpl {
|
|
|
15588
15716
|
}
|
|
15589
15717
|
async createDiffTrigger(options) {
|
|
15590
15718
|
await this.db.waitForReady();
|
|
15591
|
-
const { source, destination, columns, when, hooks,
|
|
15719
|
+
const { source, destination, columns, when, hooks, setupContext,
|
|
15592
15720
|
// Fall back to the provided default if not given on this level
|
|
15593
15721
|
useStorage = this.defaultConfig.useStorageByDefault } = options;
|
|
15594
15722
|
const operations = Object.keys(when);
|
|
@@ -15643,13 +15771,20 @@ class TriggerManagerImpl {
|
|
|
15643
15771
|
* we need to ensure we can cleanup the created resources.
|
|
15644
15772
|
* We unfortunately cannot rely on transaction rollback.
|
|
15645
15773
|
*/
|
|
15646
|
-
const cleanup = async () => {
|
|
15774
|
+
const cleanup = async (options) => {
|
|
15775
|
+
const { context } = options ?? {};
|
|
15647
15776
|
disposeWarningListener();
|
|
15648
|
-
|
|
15777
|
+
const doCleanup = async (tx) => {
|
|
15649
15778
|
await this.removeTriggers(tx, triggerIds);
|
|
15650
|
-
await tx.execute(
|
|
15779
|
+
await tx.execute(`DROP TABLE IF EXISTS ${destination};`);
|
|
15651
15780
|
await releaseStorageClaim?.();
|
|
15652
|
-
}
|
|
15781
|
+
};
|
|
15782
|
+
if (context) {
|
|
15783
|
+
await doCleanup(context);
|
|
15784
|
+
}
|
|
15785
|
+
else {
|
|
15786
|
+
await this.db.writeLock(doCleanup);
|
|
15787
|
+
}
|
|
15653
15788
|
};
|
|
15654
15789
|
const setup = async (tx) => {
|
|
15655
15790
|
// Allow user code to execute in this lock context before the trigger is created.
|
|
@@ -15723,12 +15858,17 @@ class TriggerManagerImpl {
|
|
|
15723
15858
|
}
|
|
15724
15859
|
};
|
|
15725
15860
|
try {
|
|
15726
|
-
|
|
15861
|
+
if (setupContext) {
|
|
15862
|
+
await setup(setupContext);
|
|
15863
|
+
}
|
|
15864
|
+
else {
|
|
15865
|
+
await this.db.writeLock(setup);
|
|
15866
|
+
}
|
|
15727
15867
|
return cleanup;
|
|
15728
15868
|
}
|
|
15729
15869
|
catch (error) {
|
|
15730
15870
|
try {
|
|
15731
|
-
await cleanup();
|
|
15871
|
+
await cleanup(setupContext ? { context: setupContext } : undefined);
|
|
15732
15872
|
}
|
|
15733
15873
|
catch (cleanupError) {
|
|
15734
15874
|
throw new AggregateError([error, cleanupError], 'Error during operation and cleanup');
|