@powersync/common 1.48.0 → 1.49.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/bundle.cjs +148 -8
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.mjs +147 -9
- package/dist/bundle.mjs.map +1 -1
- package/dist/bundle.node.cjs +148 -8
- package/dist/bundle.node.cjs.map +1 -1
- package/dist/bundle.node.mjs +147 -9
- package/dist/bundle.node.mjs.map +1 -1
- package/dist/index.d.cts +64 -12
- package/lib/client/triggers/TriggerManager.d.ts +13 -1
- package/lib/client/triggers/TriggerManagerImpl.d.ts +2 -2
- package/lib/client/triggers/TriggerManagerImpl.js +19 -7
- package/lib/client/triggers/TriggerManagerImpl.js.map +1 -1
- package/lib/db/DBAdapter.d.ts +48 -8
- package/lib/db/DBAdapter.js +126 -0
- package/lib/db/DBAdapter.js.map +1 -1
- package/package.json +1 -1
- package/src/client/triggers/TriggerManager.ts +15 -2
- package/src/client/triggers/TriggerManagerImpl.ts +18 -6
- package/src/db/DBAdapter.ts +160 -8
package/dist/bundle.mjs
CHANGED
|
@@ -1681,6 +1681,49 @@ var Logger = /*@__PURE__*/getDefaultExportFromCjs(loggerExports);
|
|
|
1681
1681
|
* Set of generic interfaces to allow PowerSync compatibility with
|
|
1682
1682
|
* different SQLite DB implementations.
|
|
1683
1683
|
*/
|
|
1684
|
+
/**
|
|
1685
|
+
* Implements {@link DBGetUtils} on a {@link SqlRunner}.
|
|
1686
|
+
*/
|
|
1687
|
+
function DBGetUtilsDefaultMixin(Base) {
|
|
1688
|
+
return class extends Base {
|
|
1689
|
+
async getAll(sql, parameters) {
|
|
1690
|
+
const res = await this.execute(sql, parameters);
|
|
1691
|
+
return res.rows?._array ?? [];
|
|
1692
|
+
}
|
|
1693
|
+
async getOptional(sql, parameters) {
|
|
1694
|
+
const res = await this.execute(sql, parameters);
|
|
1695
|
+
return res.rows?.item(0) ?? null;
|
|
1696
|
+
}
|
|
1697
|
+
async get(sql, parameters) {
|
|
1698
|
+
const res = await this.execute(sql, parameters);
|
|
1699
|
+
const first = res.rows?.item(0);
|
|
1700
|
+
if (!first) {
|
|
1701
|
+
throw new Error('Result set is empty');
|
|
1702
|
+
}
|
|
1703
|
+
return first;
|
|
1704
|
+
}
|
|
1705
|
+
async executeBatch(query, params = []) {
|
|
1706
|
+
// If this context can run batch statements natively, use that.
|
|
1707
|
+
// @ts-ignore
|
|
1708
|
+
if (super.executeBatch) {
|
|
1709
|
+
// @ts-ignore
|
|
1710
|
+
return super.executeBatch(query, params);
|
|
1711
|
+
}
|
|
1712
|
+
// Emulate executeBatch by running statements individually.
|
|
1713
|
+
let lastInsertId;
|
|
1714
|
+
let rowsAffected = 0;
|
|
1715
|
+
for (const set of params) {
|
|
1716
|
+
const result = await this.execute(query, set);
|
|
1717
|
+
lastInsertId = result.insertId;
|
|
1718
|
+
rowsAffected += result.rowsAffected;
|
|
1719
|
+
}
|
|
1720
|
+
return {
|
|
1721
|
+
rowsAffected,
|
|
1722
|
+
insertId: lastInsertId
|
|
1723
|
+
};
|
|
1724
|
+
}
|
|
1725
|
+
};
|
|
1726
|
+
}
|
|
1684
1727
|
/**
|
|
1685
1728
|
* Update table operation numbers from SQLite
|
|
1686
1729
|
*/
|
|
@@ -1690,6 +1733,89 @@ var RowUpdateType;
|
|
|
1690
1733
|
RowUpdateType[RowUpdateType["SQLITE_DELETE"] = 9] = "SQLITE_DELETE";
|
|
1691
1734
|
RowUpdateType[RowUpdateType["SQLITE_UPDATE"] = 23] = "SQLITE_UPDATE";
|
|
1692
1735
|
})(RowUpdateType || (RowUpdateType = {}));
|
|
1736
|
+
/**
|
|
1737
|
+
* A mixin to implement {@link DBAdapter} by delegating to {@link ConnectionPool.readLock} and
|
|
1738
|
+
* {@link ConnectionPool.writeLock}.
|
|
1739
|
+
*/
|
|
1740
|
+
function DBAdapterDefaultMixin(Base) {
|
|
1741
|
+
return class extends Base {
|
|
1742
|
+
readTransaction(fn, options) {
|
|
1743
|
+
return this.readLock((ctx) => TransactionImplementation.runWith(ctx, fn), options);
|
|
1744
|
+
}
|
|
1745
|
+
writeTransaction(fn, options) {
|
|
1746
|
+
return this.writeLock((ctx) => TransactionImplementation.runWith(ctx, fn), options);
|
|
1747
|
+
}
|
|
1748
|
+
getAll(sql, parameters) {
|
|
1749
|
+
return this.readLock((ctx) => ctx.getAll(sql, parameters));
|
|
1750
|
+
}
|
|
1751
|
+
getOptional(sql, parameters) {
|
|
1752
|
+
return this.readLock((ctx) => ctx.getOptional(sql, parameters));
|
|
1753
|
+
}
|
|
1754
|
+
get(sql, parameters) {
|
|
1755
|
+
return this.readLock((ctx) => ctx.get(sql, parameters));
|
|
1756
|
+
}
|
|
1757
|
+
execute(query, params) {
|
|
1758
|
+
return this.writeLock((ctx) => ctx.execute(query, params));
|
|
1759
|
+
}
|
|
1760
|
+
executeRaw(query, params) {
|
|
1761
|
+
return this.writeLock((ctx) => ctx.executeRaw(query, params));
|
|
1762
|
+
}
|
|
1763
|
+
executeBatch(query, params) {
|
|
1764
|
+
return this.writeTransaction((tx) => tx.executeBatch(query, params));
|
|
1765
|
+
}
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1768
|
+
class BaseTransaction {
|
|
1769
|
+
inner;
|
|
1770
|
+
finalized = false;
|
|
1771
|
+
constructor(inner) {
|
|
1772
|
+
this.inner = inner;
|
|
1773
|
+
}
|
|
1774
|
+
async commit() {
|
|
1775
|
+
if (this.finalized) {
|
|
1776
|
+
return { rowsAffected: 0 };
|
|
1777
|
+
}
|
|
1778
|
+
this.finalized = true;
|
|
1779
|
+
return this.inner.execute('COMMIT');
|
|
1780
|
+
}
|
|
1781
|
+
async rollback() {
|
|
1782
|
+
if (this.finalized) {
|
|
1783
|
+
return { rowsAffected: 0 };
|
|
1784
|
+
}
|
|
1785
|
+
this.finalized = true;
|
|
1786
|
+
return this.inner.execute('ROLLBACK');
|
|
1787
|
+
}
|
|
1788
|
+
execute(query, params) {
|
|
1789
|
+
return this.inner.execute(query, params);
|
|
1790
|
+
}
|
|
1791
|
+
executeRaw(query, params) {
|
|
1792
|
+
return this.inner.executeRaw(query, params);
|
|
1793
|
+
}
|
|
1794
|
+
executeBatch(query, params) {
|
|
1795
|
+
return this.inner.executeBatch(query, params);
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
class TransactionImplementation extends DBGetUtilsDefaultMixin(BaseTransaction) {
|
|
1799
|
+
static async runWith(ctx, fn) {
|
|
1800
|
+
let tx = new TransactionImplementation(ctx);
|
|
1801
|
+
try {
|
|
1802
|
+
await ctx.execute('BEGIN IMMEDIATE');
|
|
1803
|
+
const result = await fn(tx);
|
|
1804
|
+
await tx.commit();
|
|
1805
|
+
return result;
|
|
1806
|
+
}
|
|
1807
|
+
catch (ex) {
|
|
1808
|
+
try {
|
|
1809
|
+
await tx.rollback();
|
|
1810
|
+
}
|
|
1811
|
+
catch (ex2) {
|
|
1812
|
+
// In rare cases, a rollback may fail.
|
|
1813
|
+
// Safe to ignore.
|
|
1814
|
+
}
|
|
1815
|
+
throw ex;
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1693
1819
|
function isBatchedUpdateNotification(update) {
|
|
1694
1820
|
return 'tables' in update;
|
|
1695
1821
|
}
|
|
@@ -10455,7 +10581,7 @@ function requireDist () {
|
|
|
10455
10581
|
|
|
10456
10582
|
var distExports = requireDist();
|
|
10457
10583
|
|
|
10458
|
-
var version = "1.
|
|
10584
|
+
var version = "1.49.0";
|
|
10459
10585
|
var PACKAGE = {
|
|
10460
10586
|
version: version};
|
|
10461
10587
|
|
|
@@ -12488,7 +12614,7 @@ class TriggerManagerImpl {
|
|
|
12488
12614
|
}
|
|
12489
12615
|
async createDiffTrigger(options) {
|
|
12490
12616
|
await this.db.waitForReady();
|
|
12491
|
-
const { source, destination, columns, when, hooks,
|
|
12617
|
+
const { source, destination, columns, when, hooks, setupContext,
|
|
12492
12618
|
// Fall back to the provided default if not given on this level
|
|
12493
12619
|
useStorage = this.defaultConfig.useStorageByDefault } = options;
|
|
12494
12620
|
const operations = Object.keys(when);
|
|
@@ -12543,13 +12669,20 @@ class TriggerManagerImpl {
|
|
|
12543
12669
|
* we need to ensure we can cleanup the created resources.
|
|
12544
12670
|
* We unfortunately cannot rely on transaction rollback.
|
|
12545
12671
|
*/
|
|
12546
|
-
const cleanup = async () => {
|
|
12672
|
+
const cleanup = async (options) => {
|
|
12673
|
+
const { context } = options ?? {};
|
|
12547
12674
|
disposeWarningListener();
|
|
12548
|
-
|
|
12675
|
+
const doCleanup = async (tx) => {
|
|
12549
12676
|
await this.removeTriggers(tx, triggerIds);
|
|
12550
|
-
await tx.execute(
|
|
12677
|
+
await tx.execute(`DROP TABLE IF EXISTS ${destination};`);
|
|
12551
12678
|
await releaseStorageClaim?.();
|
|
12552
|
-
}
|
|
12679
|
+
};
|
|
12680
|
+
if (context) {
|
|
12681
|
+
await doCleanup(context);
|
|
12682
|
+
}
|
|
12683
|
+
else {
|
|
12684
|
+
await this.db.writeLock(doCleanup);
|
|
12685
|
+
}
|
|
12553
12686
|
};
|
|
12554
12687
|
const setup = async (tx) => {
|
|
12555
12688
|
// Allow user code to execute in this lock context before the trigger is created.
|
|
@@ -12623,12 +12756,17 @@ class TriggerManagerImpl {
|
|
|
12623
12756
|
}
|
|
12624
12757
|
};
|
|
12625
12758
|
try {
|
|
12626
|
-
|
|
12759
|
+
if (setupContext) {
|
|
12760
|
+
await setup(setupContext);
|
|
12761
|
+
}
|
|
12762
|
+
else {
|
|
12763
|
+
await this.db.writeLock(setup);
|
|
12764
|
+
}
|
|
12627
12765
|
return cleanup;
|
|
12628
12766
|
}
|
|
12629
12767
|
catch (error) {
|
|
12630
12768
|
try {
|
|
12631
|
-
await cleanup();
|
|
12769
|
+
await cleanup(setupContext ? { context: setupContext } : undefined);
|
|
12632
12770
|
}
|
|
12633
12771
|
catch (cleanupError) {
|
|
12634
12772
|
throw new AggregateError([error, cleanupError], 'Error during operation and cleanup');
|
|
@@ -14373,5 +14511,5 @@ const parseQuery = (query, parameters) => {
|
|
|
14373
14511
|
return { sqlStatement, parameters: parameters };
|
|
14374
14512
|
};
|
|
14375
14513
|
|
|
14376
|
-
export { ATTACHMENT_TABLE, AbortOperation, AbstractPowerSyncDatabase, AbstractPowerSyncDatabaseOpenFactory, AbstractQueryProcessor, AbstractRemote, AbstractStreamingSyncImplementation, ArrayComparator, AttachmentContext, AttachmentQueue, AttachmentService, AttachmentState, AttachmentTable, BaseObserver, Column, ColumnType, ConnectionClosedError, ConnectionManager, ControlledExecutor, CrudBatch, CrudEntry, CrudTransaction, DEFAULT_CRUD_BATCH_LIMIT, DEFAULT_CRUD_UPLOAD_THROTTLE_MS, DEFAULT_INDEX_COLUMN_OPTIONS, DEFAULT_INDEX_OPTIONS, DEFAULT_LOCK_TIMEOUT_MS, DEFAULT_POWERSYNC_CLOSE_OPTIONS, DEFAULT_POWERSYNC_DB_OPTIONS, DEFAULT_PRESSURE_LIMITS, DEFAULT_REMOTE_LOGGER, DEFAULT_REMOTE_OPTIONS, DEFAULT_RETRY_DELAY_MS, DEFAULT_ROW_COMPARATOR, DEFAULT_STREAMING_SYNC_OPTIONS, DEFAULT_STREAM_CONNECTION_OPTIONS, DEFAULT_SYNC_CLIENT_IMPLEMENTATION, DEFAULT_TABLE_OPTIONS, DEFAULT_WATCH_QUERY_OPTIONS, DEFAULT_WATCH_THROTTLE_MS, DataStream, DiffTriggerOperation, DifferentialQueryProcessor, EMPTY_DIFFERENTIAL, EncodingType, FalsyComparator, FetchImplementationProvider, FetchStrategy, GetAllQuery, Index, IndexedColumn, InvalidSQLCharacters, LockType, LogLevel, MAX_AMOUNT_OF_COLUMNS, MAX_OP_ID, MEMORY_TRIGGER_CLAIM_MANAGER, OnChangeQueryProcessor, OpType, OpTypeEnum, OplogEntry, PSInternalTable, PowerSyncControlCommand, RowUpdateType, Schema, SqliteBucketStorage, SyncClientImplementation, SyncDataBatch, SyncDataBucket, SyncProgress, SyncStatus, SyncStreamConnectionMethod, SyncingService, Table, TableV2, TriggerManagerImpl, UpdateType, UploadQueueStats, WatchedQueryListenerEvent, attachmentFromSql, column, compilableQueryWatch, createBaseLogger, createLogger, extractTableUpdates, isBatchedUpdateNotification, isContinueCheckpointRequest, isDBAdapter, isPowerSyncDatabaseOptionsWithSettings, isSQLOpenFactory, isSQLOpenOptions, isStreamingKeepalive, isStreamingSyncCheckpoint, isStreamingSyncCheckpointComplete, isStreamingSyncCheckpointDiff, isStreamingSyncCheckpointPartiallyComplete, isStreamingSyncData, isSyncNewCheckpointRequest, mutexRunExclusive, parseQuery, runOnSchemaChange, sanitizeSQL, sanitizeUUID };
|
|
14514
|
+
export { ATTACHMENT_TABLE, AbortOperation, AbstractPowerSyncDatabase, AbstractPowerSyncDatabaseOpenFactory, AbstractQueryProcessor, AbstractRemote, AbstractStreamingSyncImplementation, ArrayComparator, AttachmentContext, AttachmentQueue, AttachmentService, AttachmentState, AttachmentTable, BaseObserver, Column, ColumnType, ConnectionClosedError, ConnectionManager, ControlledExecutor, CrudBatch, CrudEntry, CrudTransaction, DBAdapterDefaultMixin, DBGetUtilsDefaultMixin, DEFAULT_CRUD_BATCH_LIMIT, DEFAULT_CRUD_UPLOAD_THROTTLE_MS, DEFAULT_INDEX_COLUMN_OPTIONS, DEFAULT_INDEX_OPTIONS, DEFAULT_LOCK_TIMEOUT_MS, DEFAULT_POWERSYNC_CLOSE_OPTIONS, DEFAULT_POWERSYNC_DB_OPTIONS, DEFAULT_PRESSURE_LIMITS, DEFAULT_REMOTE_LOGGER, DEFAULT_REMOTE_OPTIONS, DEFAULT_RETRY_DELAY_MS, DEFAULT_ROW_COMPARATOR, DEFAULT_STREAMING_SYNC_OPTIONS, DEFAULT_STREAM_CONNECTION_OPTIONS, DEFAULT_SYNC_CLIENT_IMPLEMENTATION, DEFAULT_TABLE_OPTIONS, DEFAULT_WATCH_QUERY_OPTIONS, DEFAULT_WATCH_THROTTLE_MS, DataStream, DiffTriggerOperation, DifferentialQueryProcessor, EMPTY_DIFFERENTIAL, EncodingType, FalsyComparator, FetchImplementationProvider, FetchStrategy, GetAllQuery, Index, IndexedColumn, InvalidSQLCharacters, LockType, LogLevel, MAX_AMOUNT_OF_COLUMNS, MAX_OP_ID, MEMORY_TRIGGER_CLAIM_MANAGER, OnChangeQueryProcessor, OpType, OpTypeEnum, OplogEntry, PSInternalTable, PowerSyncControlCommand, RowUpdateType, Schema, SqliteBucketStorage, SyncClientImplementation, SyncDataBatch, SyncDataBucket, SyncProgress, SyncStatus, SyncStreamConnectionMethod, SyncingService, Table, TableV2, TriggerManagerImpl, UpdateType, UploadQueueStats, WatchedQueryListenerEvent, attachmentFromSql, column, compilableQueryWatch, createBaseLogger, createLogger, extractTableUpdates, isBatchedUpdateNotification, isContinueCheckpointRequest, isDBAdapter, isPowerSyncDatabaseOptionsWithSettings, isSQLOpenFactory, isSQLOpenOptions, isStreamingKeepalive, isStreamingSyncCheckpoint, isStreamingSyncCheckpointComplete, isStreamingSyncCheckpointDiff, isStreamingSyncCheckpointPartiallyComplete, isStreamingSyncData, isSyncNewCheckpointRequest, mutexRunExclusive, parseQuery, runOnSchemaChange, sanitizeSQL, sanitizeUUID };
|
|
14377
14515
|
//# sourceMappingURL=bundle.mjs.map
|