@powersync/common 0.0.0-dev-20240920103931 → 0.0.0-dev-20241107150304
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.
|
@@ -56,6 +56,8 @@ export interface SQLWatchOptions {
|
|
|
56
56
|
/** The minimum interval between queries. */
|
|
57
57
|
throttleMs?: number;
|
|
58
58
|
/**
|
|
59
|
+
* @deprecated All tables specified in {@link tables} will be watched, including PowerSync tables with prefixes.
|
|
60
|
+
*
|
|
59
61
|
* Allows for watching any SQL table
|
|
60
62
|
* by not removing PowerSync table name prefixes
|
|
61
63
|
*/
|
|
@@ -90,6 +92,7 @@ export declare const DEFAULT_POWERSYNC_DB_OPTIONS: {
|
|
|
90
92
|
logger: Logger.ILogger;
|
|
91
93
|
crudUploadThrottleMs: number;
|
|
92
94
|
};
|
|
95
|
+
export declare const DEFAULT_CRUD_BATCH_LIMIT = 100;
|
|
93
96
|
/**
|
|
94
97
|
* Requesting nested or recursive locks can block the application in some circumstances.
|
|
95
98
|
* This default lock timeout will act as a failsafe to throw an error if a lock cannot
|
|
@@ -230,7 +233,7 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
230
233
|
* data by transaction. One batch may contain data from multiple transactions,
|
|
231
234
|
* and a single transaction may be split over multiple batches.
|
|
232
235
|
*/
|
|
233
|
-
getCrudBatch(limit
|
|
236
|
+
getCrudBatch(limit?: number): Promise<CrudBatch | null>;
|
|
234
237
|
/**
|
|
235
238
|
* Get the next recorded transaction to upload.
|
|
236
239
|
*
|
|
@@ -27,6 +27,7 @@ export const DEFAULT_POWERSYNC_DB_OPTIONS = {
|
|
|
27
27
|
logger: Logger.get('PowerSyncDatabase'),
|
|
28
28
|
crudUploadThrottleMs: DEFAULT_CRUD_UPLOAD_THROTTLE_MS
|
|
29
29
|
};
|
|
30
|
+
export const DEFAULT_CRUD_BATCH_LIMIT = 100;
|
|
30
31
|
/**
|
|
31
32
|
* Requesting nested or recursive locks can block the application in some circumstances.
|
|
32
33
|
* This default lock timeout will act as a failsafe to throw an error if a lock cannot
|
|
@@ -172,11 +173,11 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
|
|
|
172
173
|
.map((n) => parseInt(n));
|
|
173
174
|
}
|
|
174
175
|
catch (e) {
|
|
175
|
-
throw new Error(`Unsupported powersync extension version. Need
|
|
176
|
+
throw new Error(`Unsupported powersync extension version. Need >=0.2.0 <1.0.0, got: ${this.sdkVersion}. Details: ${e.message}`);
|
|
176
177
|
}
|
|
177
|
-
// Validate
|
|
178
|
-
if (versionInts[0] != 0 || versionInts[1]
|
|
179
|
-
throw new Error(`Unsupported powersync extension version. Need
|
|
178
|
+
// Validate >=0.2.0 <1.0.0
|
|
179
|
+
if (versionInts[0] != 0 || versionInts[1] < 2 || versionInts[2] < 0) {
|
|
180
|
+
throw new Error(`Unsupported powersync extension version. Need >=0.2.0 <1.0.0, got: ${this.sdkVersion}`);
|
|
180
181
|
}
|
|
181
182
|
}
|
|
182
183
|
async updateHasSynced() {
|
|
@@ -326,7 +327,7 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
|
|
|
326
327
|
* data by transaction. One batch may contain data from multiple transactions,
|
|
327
328
|
* and a single transaction may be split over multiple batches.
|
|
328
329
|
*/
|
|
329
|
-
async getCrudBatch(limit) {
|
|
330
|
+
async getCrudBatch(limit = DEFAULT_CRUD_BATCH_LIMIT) {
|
|
330
331
|
const result = await this.getAll(`SELECT id, tx_id, data FROM ${PSInternalTable.CRUD} ORDER BY id ASC LIMIT ?`, [limit + 1]);
|
|
331
332
|
const all = result.map((row) => CrudEntry.fromRow(row)) ?? [];
|
|
332
333
|
let haveMore = false;
|
|
@@ -588,7 +589,7 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
|
|
|
588
589
|
throw new Error('onChange is required');
|
|
589
590
|
}
|
|
590
591
|
const resolvedOptions = options ?? {};
|
|
591
|
-
const watchedTables = new Set(resolvedOptions
|
|
592
|
+
const watchedTables = new Set((resolvedOptions?.tables ?? []).flatMap((table) => [table, `ps_data__${table}`, `ps_data_local__${table}`]));
|
|
592
593
|
const changedTables = new Set();
|
|
593
594
|
const throttleMs = resolvedOptions.throttleMs ?? DEFAULT_WATCH_THROTTLE_MS;
|
|
594
595
|
const executor = new ControlledExecutor(async (e) => {
|
|
@@ -602,8 +603,7 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
|
|
|
602
603
|
const dispose = this.database.registerListener({
|
|
603
604
|
tablesUpdated: async (update) => {
|
|
604
605
|
try {
|
|
605
|
-
|
|
606
|
-
this.processTableUpdates(update, rawTableNames, changedTables);
|
|
606
|
+
this.processTableUpdates(update, changedTables);
|
|
607
607
|
flushTableUpdates();
|
|
608
608
|
}
|
|
609
609
|
catch (error) {
|
|
@@ -652,19 +652,11 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
|
|
|
652
652
|
}
|
|
653
653
|
changedTables.clear();
|
|
654
654
|
}
|
|
655
|
-
processTableUpdates(updateNotification,
|
|
655
|
+
processTableUpdates(updateNotification, changedTables) {
|
|
656
656
|
const tables = isBatchedUpdateNotification(updateNotification)
|
|
657
657
|
? updateNotification.tables
|
|
658
658
|
: [updateNotification.table];
|
|
659
|
-
const
|
|
660
|
-
if (!filteredTables.length) {
|
|
661
|
-
return;
|
|
662
|
-
}
|
|
663
|
-
// Remove any PowerSync table prefixes if necessary
|
|
664
|
-
const mappedTableNames = rawTableNames
|
|
665
|
-
? filteredTables
|
|
666
|
-
: filteredTables.map((t) => t.replace(POWERSYNC_TABLE_MATCH, ''));
|
|
667
|
-
for (const table of mappedTableNames) {
|
|
659
|
+
for (const table of tables) {
|
|
668
660
|
changedTables.add(table);
|
|
669
661
|
}
|
|
670
662
|
}
|
|
@@ -6,6 +6,7 @@ import { WebsocketClientTransport } from 'rsocket-websocket-client';
|
|
|
6
6
|
import { AbortOperation } from '../../../utils/AbortOperation.js';
|
|
7
7
|
import { DataStream } from '../../../utils/DataStream.js';
|
|
8
8
|
import { version as POWERSYNC_JS_VERSION } from '../../../../package.json';
|
|
9
|
+
const POWERSYNC_TRAILING_SLASH_MATCH = /\/+$/;
|
|
9
10
|
// Refresh at least 30 sec before it expires
|
|
10
11
|
const REFRESH_CREDENTIALS_SAFETY_PERIOD_MS = 30_000;
|
|
11
12
|
const SYNC_QUEUE_REQUEST_N = 10;
|
|
@@ -61,6 +62,9 @@ export class AbstractRemote {
|
|
|
61
62
|
return this.credentials;
|
|
62
63
|
}
|
|
63
64
|
this.credentials = await this.connector.fetchCredentials();
|
|
65
|
+
if (this.credentials?.endpoint.match(POWERSYNC_TRAILING_SLASH_MATCH)) {
|
|
66
|
+
throw new Error(`A trailing forward slash "/" was found in the fetchCredentials endpoint: "${this.credentials.endpoint}". Remove the trailing forward slash "/" to fix this error.`);
|
|
67
|
+
}
|
|
64
68
|
return this.credentials;
|
|
65
69
|
}
|
|
66
70
|
getUserAgent() {
|
|
@@ -2,9 +2,9 @@ import Logger from 'js-logger';
|
|
|
2
2
|
import { SyncStatus } from '../../../db/crud/SyncStatus.js';
|
|
3
3
|
import { AbortOperation } from '../../../utils/AbortOperation.js';
|
|
4
4
|
import { BaseObserver } from '../../../utils/BaseObserver.js';
|
|
5
|
+
import { throttleLeadingTrailing } from '../../../utils/throttle.js';
|
|
5
6
|
import { SyncDataBucket } from '../bucket/SyncDataBucket.js';
|
|
6
7
|
import { isStreamingKeepalive, isStreamingSyncCheckpoint, isStreamingSyncCheckpointComplete, isStreamingSyncCheckpointDiff, isStreamingSyncData } from './streaming-sync-types.js';
|
|
7
|
-
import { throttleLeadingTrailing } from '../../../utils/throttle.js';
|
|
8
8
|
export var LockType;
|
|
9
9
|
(function (LockType) {
|
|
10
10
|
LockType["CRUD"] = "crud";
|
|
@@ -121,7 +121,7 @@ export class AbstractStreamingSyncImplementation extends BaseObserver {
|
|
|
121
121
|
*/
|
|
122
122
|
const nextCrudItem = await this.options.adapter.nextCrudItem();
|
|
123
123
|
if (nextCrudItem) {
|
|
124
|
-
if (nextCrudItem.
|
|
124
|
+
if (nextCrudItem.clientId == checkedCrudItem?.clientId) {
|
|
125
125
|
// This will force a higher log level than exceptions which are caught here.
|
|
126
126
|
this.logger.warn(`Potentially previously uploaded CRUD entries are still present in the upload queue.
|
|
127
127
|
Make sure to handle uploads and complete CRUD transactions or batches by calling and awaiting their [.complete()] method.
|