@powersync/common 0.0.0-dev-20260503073249 → 0.0.0-dev-20260504100448
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 +14 -659
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.mjs +15 -648
- package/dist/bundle.mjs.map +1 -1
- package/dist/bundle.node.cjs +14 -659
- package/dist/bundle.node.cjs.map +1 -1
- package/dist/bundle.node.mjs +15 -648
- package/dist/bundle.node.mjs.map +1 -1
- package/dist/index.d.cts +19 -358
- package/legacy/sync_protocol.d.ts +103 -0
- package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +1 -63
- package/lib/client/sync/bucket/BucketStorageAdapter.js.map +1 -1
- package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +1 -28
- package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -162
- package/lib/client/sync/bucket/SqliteBucketStorage.js.map +1 -1
- package/lib/client/sync/stream/AbstractRemote.d.ts +2 -12
- package/lib/client/sync/stream/AbstractRemote.js +3 -13
- package/lib/client/sync/stream/AbstractRemote.js.map +1 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +9 -35
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +11 -338
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -1
- package/lib/client/sync/stream/JsonValue.d.ts +7 -0
- package/lib/client/sync/stream/JsonValue.js +2 -0
- package/lib/client/sync/stream/JsonValue.js.map +1 -0
- package/lib/client/sync/stream/core-instruction.d.ts +1 -2
- package/lib/client/sync/stream/core-instruction.js.map +1 -1
- package/lib/index.d.ts +1 -5
- package/lib/index.js +1 -5
- package/lib/index.js.map +1 -1
- package/package.json +7 -4
- package/src/client/sync/bucket/BucketStorageAdapter.ts +1 -70
- package/src/client/sync/bucket/SqliteBucketStorage.ts +1 -197
- package/src/client/sync/stream/AbstractRemote.ts +5 -27
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +22 -402
- package/src/client/sync/stream/JsonValue.ts +8 -0
- package/src/client/sync/stream/core-instruction.ts +1 -2
- package/src/index.ts +1 -5
- package/lib/client/sync/bucket/OpType.d.ts +0 -16
- package/lib/client/sync/bucket/OpType.js +0 -23
- package/lib/client/sync/bucket/OpType.js.map +0 -1
- package/lib/client/sync/bucket/OplogEntry.d.ts +0 -23
- package/lib/client/sync/bucket/OplogEntry.js +0 -36
- package/lib/client/sync/bucket/OplogEntry.js.map +0 -1
- package/lib/client/sync/bucket/SyncDataBatch.d.ts +0 -6
- package/lib/client/sync/bucket/SyncDataBatch.js +0 -12
- package/lib/client/sync/bucket/SyncDataBatch.js.map +0 -1
- package/lib/client/sync/bucket/SyncDataBucket.d.ts +0 -40
- package/lib/client/sync/bucket/SyncDataBucket.js +0 -40
- package/lib/client/sync/bucket/SyncDataBucket.js.map +0 -1
- package/lib/client/sync/stream/streaming-sync-types.d.ts +0 -143
- package/lib/client/sync/stream/streaming-sync-types.js +0 -26
- package/lib/client/sync/stream/streaming-sync-types.js.map +0 -1
- package/src/client/sync/bucket/OpType.ts +0 -23
- package/src/client/sync/bucket/OplogEntry.ts +0 -50
- package/src/client/sync/bucket/SyncDataBatch.ts +0 -11
- package/src/client/sync/bucket/SyncDataBucket.ts +0 -49
- package/src/client/sync/stream/streaming-sync-types.ts +0 -210
package/dist/bundle.node.cjs
CHANGED
|
@@ -3337,103 +3337,6 @@ class AbortOperation extends Error {
|
|
|
3337
3337
|
}
|
|
3338
3338
|
}
|
|
3339
3339
|
|
|
3340
|
-
exports.OpTypeEnum = void 0;
|
|
3341
|
-
(function (OpTypeEnum) {
|
|
3342
|
-
OpTypeEnum[OpTypeEnum["CLEAR"] = 1] = "CLEAR";
|
|
3343
|
-
OpTypeEnum[OpTypeEnum["MOVE"] = 2] = "MOVE";
|
|
3344
|
-
OpTypeEnum[OpTypeEnum["PUT"] = 3] = "PUT";
|
|
3345
|
-
OpTypeEnum[OpTypeEnum["REMOVE"] = 4] = "REMOVE";
|
|
3346
|
-
})(exports.OpTypeEnum || (exports.OpTypeEnum = {}));
|
|
3347
|
-
/**
|
|
3348
|
-
* Used internally for sync buckets.
|
|
3349
|
-
*/
|
|
3350
|
-
class OpType {
|
|
3351
|
-
value;
|
|
3352
|
-
static fromJSON(jsonValue) {
|
|
3353
|
-
return new OpType(exports.OpTypeEnum[jsonValue]);
|
|
3354
|
-
}
|
|
3355
|
-
constructor(value) {
|
|
3356
|
-
this.value = value;
|
|
3357
|
-
}
|
|
3358
|
-
toJSON() {
|
|
3359
|
-
return Object.entries(exports.OpTypeEnum).find(([, value]) => value === this.value)[0];
|
|
3360
|
-
}
|
|
3361
|
-
}
|
|
3362
|
-
|
|
3363
|
-
class OplogEntry {
|
|
3364
|
-
op_id;
|
|
3365
|
-
op;
|
|
3366
|
-
checksum;
|
|
3367
|
-
subkey;
|
|
3368
|
-
object_type;
|
|
3369
|
-
object_id;
|
|
3370
|
-
data;
|
|
3371
|
-
static fromRow(row) {
|
|
3372
|
-
return new OplogEntry(row.op_id, OpType.fromJSON(row.op), row.checksum, row.subkey, row.object_type, row.object_id, row.data);
|
|
3373
|
-
}
|
|
3374
|
-
constructor(op_id, op, checksum, subkey, object_type, object_id, data) {
|
|
3375
|
-
this.op_id = op_id;
|
|
3376
|
-
this.op = op;
|
|
3377
|
-
this.checksum = checksum;
|
|
3378
|
-
this.subkey = subkey;
|
|
3379
|
-
this.object_type = object_type;
|
|
3380
|
-
this.object_id = object_id;
|
|
3381
|
-
this.data = data;
|
|
3382
|
-
}
|
|
3383
|
-
toJSON(fixedKeyEncoding = false) {
|
|
3384
|
-
return {
|
|
3385
|
-
op_id: this.op_id,
|
|
3386
|
-
op: this.op.toJSON(),
|
|
3387
|
-
object_type: this.object_type,
|
|
3388
|
-
object_id: this.object_id,
|
|
3389
|
-
checksum: this.checksum,
|
|
3390
|
-
data: this.data,
|
|
3391
|
-
// Older versions of the JS SDK used to always JSON.stringify here. That has always been wrong,
|
|
3392
|
-
// but we need to migrate gradually to not break existing databases.
|
|
3393
|
-
subkey: fixedKeyEncoding ? this.subkey : JSON.stringify(this.subkey)
|
|
3394
|
-
};
|
|
3395
|
-
}
|
|
3396
|
-
}
|
|
3397
|
-
|
|
3398
|
-
class SyncDataBucket {
|
|
3399
|
-
bucket;
|
|
3400
|
-
data;
|
|
3401
|
-
has_more;
|
|
3402
|
-
after;
|
|
3403
|
-
next_after;
|
|
3404
|
-
static fromRow(row) {
|
|
3405
|
-
return new SyncDataBucket(row.bucket, row.data.map((entry) => OplogEntry.fromRow(entry)), row.has_more ?? false, row.after, row.next_after);
|
|
3406
|
-
}
|
|
3407
|
-
constructor(bucket, data,
|
|
3408
|
-
/**
|
|
3409
|
-
* True if the response does not contain all the data for this bucket, and another request must be made.
|
|
3410
|
-
*/
|
|
3411
|
-
has_more,
|
|
3412
|
-
/**
|
|
3413
|
-
* The `after` specified in the request.
|
|
3414
|
-
*/
|
|
3415
|
-
after,
|
|
3416
|
-
/**
|
|
3417
|
-
* Use this for the next request.
|
|
3418
|
-
*/
|
|
3419
|
-
next_after) {
|
|
3420
|
-
this.bucket = bucket;
|
|
3421
|
-
this.data = data;
|
|
3422
|
-
this.has_more = has_more;
|
|
3423
|
-
this.after = after;
|
|
3424
|
-
this.next_after = next_after;
|
|
3425
|
-
}
|
|
3426
|
-
toJSON(fixedKeyEncoding = false) {
|
|
3427
|
-
return {
|
|
3428
|
-
bucket: this.bucket,
|
|
3429
|
-
has_more: this.has_more,
|
|
3430
|
-
after: this.after,
|
|
3431
|
-
next_after: this.next_after,
|
|
3432
|
-
data: this.data.map((entry) => entry.toJSON(fixedKeyEncoding))
|
|
3433
|
-
};
|
|
3434
|
-
}
|
|
3435
|
-
}
|
|
3436
|
-
|
|
3437
3340
|
var dist = {};
|
|
3438
3341
|
|
|
3439
3342
|
var Codecs = {};
|
|
@@ -8775,22 +8678,12 @@ class AbstractRemote {
|
|
|
8775
8678
|
* Returns a data stream of sync line data, fetched via RSocket-over-WebSocket.
|
|
8776
8679
|
*
|
|
8777
8680
|
* The only mechanism to abort the returned stream is to use the abort signal in {@link SocketSyncStreamOptions}.
|
|
8778
|
-
*
|
|
8779
|
-
* @param bson A BSON encoder and decoder. When set, the data stream will be requested with a BSON payload
|
|
8780
|
-
* (required for compatibility with older sync services).
|
|
8781
8681
|
*/
|
|
8782
|
-
async socketStreamRaw(options
|
|
8682
|
+
async socketStreamRaw(options) {
|
|
8783
8683
|
const { path, fetchStrategy = exports.FetchStrategy.Buffered } = options;
|
|
8784
|
-
const mimeType =
|
|
8684
|
+
const mimeType = 'application/json';
|
|
8785
8685
|
function toBuffer(js) {
|
|
8786
|
-
|
|
8787
|
-
if (bson != null) {
|
|
8788
|
-
contents = bson.serialize(js);
|
|
8789
|
-
}
|
|
8790
|
-
else {
|
|
8791
|
-
contents = JSON.stringify(js);
|
|
8792
|
-
}
|
|
8793
|
-
return node_buffer.Buffer.from(contents);
|
|
8686
|
+
return node_buffer.Buffer.from(JSON.stringify(js));
|
|
8794
8687
|
}
|
|
8795
8688
|
const syncQueueRequestSize = fetchStrategy == exports.FetchStrategy.Buffered ? 10 : 1;
|
|
8796
8689
|
const request = await this.buildRequest(path);
|
|
@@ -9092,32 +8985,6 @@ function coreStatusToJs(status) {
|
|
|
9092
8985
|
};
|
|
9093
8986
|
}
|
|
9094
8987
|
|
|
9095
|
-
function isStreamingSyncData(line) {
|
|
9096
|
-
return line.data != null;
|
|
9097
|
-
}
|
|
9098
|
-
function isStreamingKeepalive(line) {
|
|
9099
|
-
return line.token_expires_in != null;
|
|
9100
|
-
}
|
|
9101
|
-
function isStreamingSyncCheckpoint(line) {
|
|
9102
|
-
return line.checkpoint != null;
|
|
9103
|
-
}
|
|
9104
|
-
function isStreamingSyncCheckpointComplete(line) {
|
|
9105
|
-
return line.checkpoint_complete != null;
|
|
9106
|
-
}
|
|
9107
|
-
function isStreamingSyncCheckpointPartiallyComplete(line) {
|
|
9108
|
-
return line.partial_checkpoint_complete != null;
|
|
9109
|
-
}
|
|
9110
|
-
function isStreamingSyncCheckpointDiff(line) {
|
|
9111
|
-
return line.checkpoint_diff != null;
|
|
9112
|
-
}
|
|
9113
|
-
function isContinueCheckpointRequest(request) {
|
|
9114
|
-
return (Array.isArray(request.buckets) &&
|
|
9115
|
-
typeof request.checkpoint_token == 'string');
|
|
9116
|
-
}
|
|
9117
|
-
function isSyncNewCheckpointRequest(request) {
|
|
9118
|
-
return typeof request.request_checkpoint == 'object';
|
|
9119
|
-
}
|
|
9120
|
-
|
|
9121
8988
|
exports.LockType = void 0;
|
|
9122
8989
|
(function (LockType) {
|
|
9123
8990
|
LockType["CRUD"] = "crud";
|
|
@@ -9130,35 +8997,21 @@ exports.SyncStreamConnectionMethod = void 0;
|
|
|
9130
8997
|
})(exports.SyncStreamConnectionMethod || (exports.SyncStreamConnectionMethod = {}));
|
|
9131
8998
|
exports.SyncClientImplementation = void 0;
|
|
9132
8999
|
(function (SyncClientImplementation) {
|
|
9133
|
-
/**
|
|
9134
|
-
* Decodes and handles sync lines received from the sync service in JavaScript.
|
|
9135
|
-
*
|
|
9136
|
-
* This is the default option.
|
|
9137
|
-
*
|
|
9138
|
-
* @deprecated We recommend the {@link RUST} client implementation for all apps. If you have issues with
|
|
9139
|
-
* the Rust client, please file an issue or reach out to us. The JavaScript client will be removed in a future
|
|
9140
|
-
* version of the PowerSync SDK.
|
|
9141
|
-
*/
|
|
9142
|
-
SyncClientImplementation["JAVASCRIPT"] = "js";
|
|
9143
9000
|
/**
|
|
9144
9001
|
* This implementation offloads the sync line decoding and handling into the PowerSync
|
|
9145
9002
|
* core extension.
|
|
9146
9003
|
*
|
|
9147
|
-
* This
|
|
9148
|
-
* recommended client implementation for all apps.
|
|
9004
|
+
* This is the only option, as an older JavaScript client implementation has been removed from the SDK.
|
|
9149
9005
|
*
|
|
9150
9006
|
* ## Compatibility warning
|
|
9151
9007
|
*
|
|
9152
9008
|
* The Rust sync client stores sync data in a format that is slightly different than the one used
|
|
9153
|
-
* by the old
|
|
9154
|
-
*
|
|
9155
|
-
* Further, the {@link JAVASCRIPT} client in recent versions of the PowerSync JS SDK (starting from
|
|
9156
|
-
* the version introducing {@link RUST} as an option) also supports the new format, so you can switch
|
|
9157
|
-
* back to {@link JAVASCRIPT} later.
|
|
9009
|
+
* by the old JavaScript client. When adopting the {@link RUST} client on existing databases, the PowerSync SDK will
|
|
9010
|
+
* migrate the format automatically.
|
|
9158
9011
|
*
|
|
9159
|
-
*
|
|
9160
|
-
*
|
|
9161
|
-
*
|
|
9012
|
+
* SDK versions supporting both the JavaScript and the Rust client support both formats with the JavaScript client
|
|
9013
|
+
* implementaiton. However, downgrading to an SDK version that only supports the JavaScript client would not be
|
|
9014
|
+
* possible anymore. Problematic SDK versions have been released before 2025-06-09.
|
|
9162
9015
|
*/
|
|
9163
9016
|
SyncClientImplementation["RUST"] = "rust";
|
|
9164
9017
|
})(exports.SyncClientImplementation || (exports.SyncClientImplementation = {}));
|
|
@@ -9181,13 +9034,7 @@ const DEFAULT_STREAM_CONNECTION_OPTIONS = {
|
|
|
9181
9034
|
serializedSchema: undefined,
|
|
9182
9035
|
includeDefaultStreams: true
|
|
9183
9036
|
};
|
|
9184
|
-
// The priority we assume when we receive checkpoint lines where no priority is set.
|
|
9185
|
-
// This is the default priority used by the sync service, but can be set to an arbitrary
|
|
9186
|
-
// value since sync services without priorities also won't send partial sync completion
|
|
9187
|
-
// messages.
|
|
9188
|
-
const FALLBACK_PRIORITY = 3;
|
|
9189
9037
|
class AbstractStreamingSyncImplementation extends BaseObserver {
|
|
9190
|
-
_lastSyncedAt;
|
|
9191
9038
|
options;
|
|
9192
9039
|
abortController;
|
|
9193
9040
|
// In rare cases, mostly for tests, uploads can be triggered without being properly connected.
|
|
@@ -9277,9 +9124,6 @@ class AbstractStreamingSyncImplementation extends BaseObserver {
|
|
|
9277
9124
|
this.crudUpdateListener = undefined;
|
|
9278
9125
|
this.uploadAbortController?.abort();
|
|
9279
9126
|
}
|
|
9280
|
-
async hasCompletedSync() {
|
|
9281
|
-
return this.options.adapter.hasCompletedSync();
|
|
9282
|
-
}
|
|
9283
9127
|
async getWriteCheckpoint() {
|
|
9284
9128
|
const clientId = await this.options.adapter.getClientId();
|
|
9285
9129
|
let path = `/write-checkpoint2.json?client_id=${clientId}`;
|
|
@@ -9361,7 +9205,7 @@ The next upload iteration will be delayed.`);
|
|
|
9361
9205
|
});
|
|
9362
9206
|
}
|
|
9363
9207
|
}
|
|
9364
|
-
this.uploadAbortController =
|
|
9208
|
+
this.uploadAbortController = undefined;
|
|
9365
9209
|
}
|
|
9366
9210
|
});
|
|
9367
9211
|
}
|
|
@@ -9521,18 +9365,6 @@ The next upload iteration will be delayed.`);
|
|
|
9521
9365
|
// iteration is active. That allows us to reconnect ASAP, instead of having to wait for the next sync line.
|
|
9522
9366
|
this.handleActiveStreamsChange?.();
|
|
9523
9367
|
}
|
|
9524
|
-
async collectLocalBucketState() {
|
|
9525
|
-
const bucketEntries = await this.options.adapter.getBucketStates();
|
|
9526
|
-
const req = bucketEntries.map((entry) => ({
|
|
9527
|
-
name: entry.bucket,
|
|
9528
|
-
after: entry.op_id
|
|
9529
|
-
}));
|
|
9530
|
-
const localDescriptions = new Map();
|
|
9531
|
-
for (const entry of bucketEntries) {
|
|
9532
|
-
localDescriptions.set(entry.bucket, null);
|
|
9533
|
-
}
|
|
9534
|
-
return [req, localDescriptions];
|
|
9535
|
-
}
|
|
9536
9368
|
/**
|
|
9537
9369
|
* Older versions of the JS SDK used to encode subkeys as JSON in {@link OplogEntry.toJSON}.
|
|
9538
9370
|
* Because subkeys are always strings, this leads to quotes being added around them in `ps_oplog`.
|
|
@@ -9574,19 +9406,13 @@ The next upload iteration will be delayed.`);
|
|
|
9574
9406
|
}
|
|
9575
9407
|
const clientImplementation = resolvedOptions.clientImplementation;
|
|
9576
9408
|
this.updateSyncStatus({ clientImplementation });
|
|
9577
|
-
|
|
9578
|
-
|
|
9579
|
-
return null;
|
|
9580
|
-
}
|
|
9581
|
-
else {
|
|
9582
|
-
await this.requireKeyFormat(true);
|
|
9583
|
-
return await this.rustSyncIteration(signal, resolvedOptions);
|
|
9584
|
-
}
|
|
9409
|
+
await this.requireKeyFormat(true);
|
|
9410
|
+
return await this.rustSyncIteration(signal, resolvedOptions);
|
|
9585
9411
|
}
|
|
9586
9412
|
});
|
|
9587
9413
|
}
|
|
9588
9414
|
async receiveSyncLines(data) {
|
|
9589
|
-
const { options, connection
|
|
9415
|
+
const { options, connection } = data;
|
|
9590
9416
|
const remote = this.options.remote;
|
|
9591
9417
|
if (connection.connectionMethod == exports.SyncStreamConnectionMethod.HTTP) {
|
|
9592
9418
|
return await remote.fetchStream(options);
|
|
@@ -9595,232 +9421,8 @@ The next upload iteration will be delayed.`);
|
|
|
9595
9421
|
return await this.options.remote.socketStreamRaw({
|
|
9596
9422
|
...options,
|
|
9597
9423
|
...{ fetchStrategy: connection.fetchStrategy }
|
|
9598
|
-
}
|
|
9599
|
-
}
|
|
9600
|
-
}
|
|
9601
|
-
async legacyStreamingSyncIteration(signal, resolvedOptions) {
|
|
9602
|
-
const rawTables = resolvedOptions.serializedSchema?.raw_tables;
|
|
9603
|
-
if (rawTables != null && rawTables.length) {
|
|
9604
|
-
this.logger.warn('Raw tables require the Rust-based sync client. The JS client will ignore them.');
|
|
9605
|
-
}
|
|
9606
|
-
if (this.activeStreams.length) {
|
|
9607
|
-
this.logger.error('Sync streams require `clientImplementation: SyncClientImplementation.RUST` when connecting.');
|
|
9608
|
-
}
|
|
9609
|
-
this.logger.debug('Streaming sync iteration started');
|
|
9610
|
-
this.options.adapter.startSession();
|
|
9611
|
-
let [req, bucketMap] = await this.collectLocalBucketState();
|
|
9612
|
-
let targetCheckpoint = null;
|
|
9613
|
-
// A checkpoint that has been validated but not applied (e.g. due to pending local writes)
|
|
9614
|
-
let pendingValidatedCheckpoint = null;
|
|
9615
|
-
const clientId = await this.options.adapter.getClientId();
|
|
9616
|
-
const usingFixedKeyFormat = await this.requireKeyFormat(false);
|
|
9617
|
-
this.logger.debug('Requesting stream from server');
|
|
9618
|
-
const syncOptions = {
|
|
9619
|
-
path: '/sync/stream',
|
|
9620
|
-
abortSignal: signal,
|
|
9621
|
-
data: {
|
|
9622
|
-
buckets: req,
|
|
9623
|
-
include_checksum: true,
|
|
9624
|
-
raw_data: true,
|
|
9625
|
-
parameters: resolvedOptions.params,
|
|
9626
|
-
app_metadata: resolvedOptions.appMetadata,
|
|
9627
|
-
client_id: clientId
|
|
9628
|
-
}
|
|
9629
|
-
};
|
|
9630
|
-
const bson = await this.options.remote.getBSON();
|
|
9631
|
-
const source = await this.receiveSyncLines({
|
|
9632
|
-
options: syncOptions,
|
|
9633
|
-
connection: resolvedOptions,
|
|
9634
|
-
bson
|
|
9635
|
-
});
|
|
9636
|
-
const stream = injectable(map(source, (line) => {
|
|
9637
|
-
if (typeof line == 'string') {
|
|
9638
|
-
return JSON.parse(line);
|
|
9639
|
-
}
|
|
9640
|
-
else {
|
|
9641
|
-
return bson.deserialize(line);
|
|
9642
|
-
}
|
|
9643
|
-
}));
|
|
9644
|
-
this.logger.debug('Stream established. Processing events');
|
|
9645
|
-
this.notifyCompletedUploads = () => {
|
|
9646
|
-
stream.inject({ crud_upload_completed: null });
|
|
9647
|
-
};
|
|
9648
|
-
while (true) {
|
|
9649
|
-
const { value: line, done } = await stream.next();
|
|
9650
|
-
if (done) {
|
|
9651
|
-
// The stream has closed while waiting
|
|
9652
|
-
return;
|
|
9653
|
-
}
|
|
9654
|
-
if ('crud_upload_completed' in line) {
|
|
9655
|
-
if (pendingValidatedCheckpoint != null) {
|
|
9656
|
-
const { applied, endIteration } = await this.applyCheckpoint(pendingValidatedCheckpoint);
|
|
9657
|
-
if (applied) {
|
|
9658
|
-
pendingValidatedCheckpoint = null;
|
|
9659
|
-
}
|
|
9660
|
-
else if (endIteration) {
|
|
9661
|
-
break;
|
|
9662
|
-
}
|
|
9663
|
-
}
|
|
9664
|
-
continue;
|
|
9665
|
-
}
|
|
9666
|
-
// A connection is active and messages are being received
|
|
9667
|
-
if (!this.syncStatus.connected) {
|
|
9668
|
-
// There is a connection now
|
|
9669
|
-
Promise.resolve().then(() => this.triggerCrudUpload());
|
|
9670
|
-
this.updateSyncStatus({
|
|
9671
|
-
connected: true
|
|
9672
|
-
});
|
|
9673
|
-
}
|
|
9674
|
-
if (isStreamingSyncCheckpoint(line)) {
|
|
9675
|
-
targetCheckpoint = line.checkpoint;
|
|
9676
|
-
// New checkpoint - existing validated checkpoint is no longer valid
|
|
9677
|
-
pendingValidatedCheckpoint = null;
|
|
9678
|
-
const bucketsToDelete = new Set(bucketMap.keys());
|
|
9679
|
-
const newBuckets = new Map();
|
|
9680
|
-
for (const checksum of line.checkpoint.buckets) {
|
|
9681
|
-
newBuckets.set(checksum.bucket, {
|
|
9682
|
-
name: checksum.bucket,
|
|
9683
|
-
priority: checksum.priority ?? FALLBACK_PRIORITY
|
|
9684
|
-
});
|
|
9685
|
-
bucketsToDelete.delete(checksum.bucket);
|
|
9686
|
-
}
|
|
9687
|
-
if (bucketsToDelete.size > 0) {
|
|
9688
|
-
this.logger.debug('Removing buckets', [...bucketsToDelete]);
|
|
9689
|
-
}
|
|
9690
|
-
bucketMap = newBuckets;
|
|
9691
|
-
await this.options.adapter.removeBuckets([...bucketsToDelete]);
|
|
9692
|
-
await this.options.adapter.setTargetCheckpoint(targetCheckpoint);
|
|
9693
|
-
await this.updateSyncStatusForStartingCheckpoint(targetCheckpoint);
|
|
9694
|
-
}
|
|
9695
|
-
else if (isStreamingSyncCheckpointComplete(line)) {
|
|
9696
|
-
const result = await this.applyCheckpoint(targetCheckpoint);
|
|
9697
|
-
if (result.endIteration) {
|
|
9698
|
-
return;
|
|
9699
|
-
}
|
|
9700
|
-
else if (!result.applied) {
|
|
9701
|
-
// "Could not apply checkpoint due to local data". We need to retry after
|
|
9702
|
-
// finishing uploads.
|
|
9703
|
-
pendingValidatedCheckpoint = targetCheckpoint;
|
|
9704
|
-
}
|
|
9705
|
-
else {
|
|
9706
|
-
// Nothing to retry later. This would likely already be null from the last
|
|
9707
|
-
// checksum or checksum_diff operation, but we make sure.
|
|
9708
|
-
pendingValidatedCheckpoint = null;
|
|
9709
|
-
}
|
|
9710
|
-
}
|
|
9711
|
-
else if (isStreamingSyncCheckpointPartiallyComplete(line)) {
|
|
9712
|
-
const priority = line.partial_checkpoint_complete.priority;
|
|
9713
|
-
this.logger.debug('Partial checkpoint complete', priority);
|
|
9714
|
-
const result = await this.options.adapter.syncLocalDatabase(targetCheckpoint, priority);
|
|
9715
|
-
if (!result.checkpointValid) {
|
|
9716
|
-
// This means checksums failed. Start again with a new checkpoint.
|
|
9717
|
-
// TODO: better back-off
|
|
9718
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
9719
|
-
return;
|
|
9720
|
-
}
|
|
9721
|
-
else if (!result.ready) ;
|
|
9722
|
-
else {
|
|
9723
|
-
// We'll keep on downloading, but can report that this priority is synced now.
|
|
9724
|
-
this.logger.debug('partial checkpoint validation succeeded');
|
|
9725
|
-
// All states with a higher priority can be deleted since this partial sync includes them.
|
|
9726
|
-
const priorityStates = this.syncStatus.priorityStatusEntries.filter((s) => s.priority <= priority);
|
|
9727
|
-
priorityStates.push({
|
|
9728
|
-
priority,
|
|
9729
|
-
lastSyncedAt: new Date(),
|
|
9730
|
-
hasSynced: true
|
|
9731
|
-
});
|
|
9732
|
-
this.updateSyncStatus({
|
|
9733
|
-
connected: true,
|
|
9734
|
-
priorityStatusEntries: priorityStates
|
|
9735
|
-
});
|
|
9736
|
-
}
|
|
9737
|
-
}
|
|
9738
|
-
else if (isStreamingSyncCheckpointDiff(line)) {
|
|
9739
|
-
// TODO: It may be faster to just keep track of the diff, instead of the entire checkpoint
|
|
9740
|
-
if (targetCheckpoint == null) {
|
|
9741
|
-
throw new Error('Checkpoint diff without previous checkpoint');
|
|
9742
|
-
}
|
|
9743
|
-
// New checkpoint - existing validated checkpoint is no longer valid
|
|
9744
|
-
pendingValidatedCheckpoint = null;
|
|
9745
|
-
const diff = line.checkpoint_diff;
|
|
9746
|
-
const newBuckets = new Map();
|
|
9747
|
-
for (const checksum of targetCheckpoint.buckets) {
|
|
9748
|
-
newBuckets.set(checksum.bucket, checksum);
|
|
9749
|
-
}
|
|
9750
|
-
for (const checksum of diff.updated_buckets) {
|
|
9751
|
-
newBuckets.set(checksum.bucket, checksum);
|
|
9752
|
-
}
|
|
9753
|
-
for (const bucket of diff.removed_buckets) {
|
|
9754
|
-
newBuckets.delete(bucket);
|
|
9755
|
-
}
|
|
9756
|
-
const newCheckpoint = {
|
|
9757
|
-
last_op_id: diff.last_op_id,
|
|
9758
|
-
buckets: [...newBuckets.values()],
|
|
9759
|
-
write_checkpoint: diff.write_checkpoint
|
|
9760
|
-
};
|
|
9761
|
-
targetCheckpoint = newCheckpoint;
|
|
9762
|
-
await this.updateSyncStatusForStartingCheckpoint(targetCheckpoint);
|
|
9763
|
-
bucketMap = new Map();
|
|
9764
|
-
newBuckets.forEach((checksum, name) => bucketMap.set(name, {
|
|
9765
|
-
name: checksum.bucket,
|
|
9766
|
-
priority: checksum.priority ?? FALLBACK_PRIORITY
|
|
9767
|
-
}));
|
|
9768
|
-
const bucketsToDelete = diff.removed_buckets;
|
|
9769
|
-
if (bucketsToDelete.length > 0) {
|
|
9770
|
-
this.logger.debug('Remove buckets', bucketsToDelete);
|
|
9771
|
-
}
|
|
9772
|
-
await this.options.adapter.removeBuckets(bucketsToDelete);
|
|
9773
|
-
await this.options.adapter.setTargetCheckpoint(targetCheckpoint);
|
|
9774
|
-
}
|
|
9775
|
-
else if (isStreamingSyncData(line)) {
|
|
9776
|
-
const { data } = line;
|
|
9777
|
-
const previousProgress = this.syncStatus.dataFlowStatus.downloadProgress;
|
|
9778
|
-
let updatedProgress = null;
|
|
9779
|
-
if (previousProgress) {
|
|
9780
|
-
updatedProgress = { ...previousProgress };
|
|
9781
|
-
const progressForBucket = updatedProgress[data.bucket];
|
|
9782
|
-
if (progressForBucket) {
|
|
9783
|
-
updatedProgress[data.bucket] = {
|
|
9784
|
-
...progressForBucket,
|
|
9785
|
-
since_last: progressForBucket.since_last + data.data.length
|
|
9786
|
-
};
|
|
9787
|
-
}
|
|
9788
|
-
}
|
|
9789
|
-
this.updateSyncStatus({
|
|
9790
|
-
dataFlow: {
|
|
9791
|
-
downloading: true,
|
|
9792
|
-
downloadProgress: updatedProgress
|
|
9793
|
-
}
|
|
9794
|
-
});
|
|
9795
|
-
await this.options.adapter.saveSyncData({ buckets: [SyncDataBucket.fromRow(data)] }, usingFixedKeyFormat);
|
|
9796
|
-
}
|
|
9797
|
-
else if (isStreamingKeepalive(line)) {
|
|
9798
|
-
const remaining_seconds = line.token_expires_in;
|
|
9799
|
-
if (remaining_seconds == 0) {
|
|
9800
|
-
// Connection would be closed automatically right after this
|
|
9801
|
-
this.logger.debug('Token expiring; reconnect');
|
|
9802
|
-
/**
|
|
9803
|
-
* For a rare case where the backend connector does not update the token
|
|
9804
|
-
* (uses the same one), this should have some delay.
|
|
9805
|
-
*/
|
|
9806
|
-
await this.delayRetry();
|
|
9807
|
-
return;
|
|
9808
|
-
}
|
|
9809
|
-
else if (remaining_seconds < 30) {
|
|
9810
|
-
this.logger.debug('Token will expire soon; reconnect');
|
|
9811
|
-
// Pre-emptively refresh the token
|
|
9812
|
-
this.options.remote.invalidateCredentials();
|
|
9813
|
-
return;
|
|
9814
|
-
}
|
|
9815
|
-
this.triggerCrudUpload();
|
|
9816
|
-
}
|
|
9817
|
-
else {
|
|
9818
|
-
this.logger.debug('Received unknown sync line', line);
|
|
9819
|
-
}
|
|
9424
|
+
});
|
|
9820
9425
|
}
|
|
9821
|
-
this.logger.debug('Stream input empty');
|
|
9822
|
-
// Connection closed. Likely due to auth issue.
|
|
9823
|
-
return;
|
|
9824
9426
|
}
|
|
9825
9427
|
async rustSyncIteration(signal, resolvedOptions) {
|
|
9826
9428
|
const syncImplementation = this;
|
|
@@ -9983,68 +9585,6 @@ The next upload iteration will be delayed.`);
|
|
|
9983
9585
|
}
|
|
9984
9586
|
return { immediateRestart: hideDisconnectOnRestart };
|
|
9985
9587
|
}
|
|
9986
|
-
async updateSyncStatusForStartingCheckpoint(checkpoint) {
|
|
9987
|
-
const localProgress = await this.options.adapter.getBucketOperationProgress();
|
|
9988
|
-
const progress = {};
|
|
9989
|
-
let invalidated = false;
|
|
9990
|
-
for (const bucket of checkpoint.buckets) {
|
|
9991
|
-
const savedProgress = localProgress[bucket.bucket];
|
|
9992
|
-
const atLast = savedProgress?.atLast ?? 0;
|
|
9993
|
-
const sinceLast = savedProgress?.sinceLast ?? 0;
|
|
9994
|
-
progress[bucket.bucket] = {
|
|
9995
|
-
// The fallback priority doesn't matter here, but 3 is the one newer versions of the sync service
|
|
9996
|
-
// will use by default.
|
|
9997
|
-
priority: bucket.priority ?? 3,
|
|
9998
|
-
at_last: atLast,
|
|
9999
|
-
since_last: sinceLast,
|
|
10000
|
-
target_count: bucket.count ?? 0
|
|
10001
|
-
};
|
|
10002
|
-
if (bucket.count != null && bucket.count < atLast + sinceLast) {
|
|
10003
|
-
// Either due to a defrag / sync rule deploy or a compaction operation, the size
|
|
10004
|
-
// of the bucket shrank so much that the local ops exceed the ops in the updated
|
|
10005
|
-
// bucket. We can't prossibly report progress in this case (it would overshoot 100%).
|
|
10006
|
-
invalidated = true;
|
|
10007
|
-
}
|
|
10008
|
-
}
|
|
10009
|
-
if (invalidated) {
|
|
10010
|
-
for (const bucket in progress) {
|
|
10011
|
-
const bucketProgress = progress[bucket];
|
|
10012
|
-
bucketProgress.at_last = 0;
|
|
10013
|
-
bucketProgress.since_last = 0;
|
|
10014
|
-
}
|
|
10015
|
-
}
|
|
10016
|
-
this.updateSyncStatus({
|
|
10017
|
-
dataFlow: {
|
|
10018
|
-
downloading: true,
|
|
10019
|
-
downloadProgress: progress
|
|
10020
|
-
}
|
|
10021
|
-
});
|
|
10022
|
-
}
|
|
10023
|
-
async applyCheckpoint(checkpoint) {
|
|
10024
|
-
let result = await this.options.adapter.syncLocalDatabase(checkpoint);
|
|
10025
|
-
if (!result.checkpointValid) {
|
|
10026
|
-
this.logger.debug(`Checksum mismatch in checkpoint ${checkpoint.last_op_id}, will reconnect`);
|
|
10027
|
-
// This means checksums failed. Start again with a new checkpoint.
|
|
10028
|
-
// TODO: better back-off
|
|
10029
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
10030
|
-
return { applied: false, endIteration: true };
|
|
10031
|
-
}
|
|
10032
|
-
else if (!result.ready) {
|
|
10033
|
-
this.logger.debug(`Could not apply checkpoint ${checkpoint.last_op_id} due to local data. We will retry applying the checkpoint after that upload is completed.`);
|
|
10034
|
-
return { applied: false, endIteration: false };
|
|
10035
|
-
}
|
|
10036
|
-
this.logger.debug(`Applied checkpoint ${checkpoint.last_op_id}`, checkpoint);
|
|
10037
|
-
this.updateSyncStatus({
|
|
10038
|
-
connected: true,
|
|
10039
|
-
lastSyncedAt: new Date(),
|
|
10040
|
-
dataFlow: {
|
|
10041
|
-
downloading: false,
|
|
10042
|
-
downloadProgress: null,
|
|
10043
|
-
downloadError: undefined
|
|
10044
|
-
}
|
|
10045
|
-
});
|
|
10046
|
-
return { applied: true, endIteration: false };
|
|
10047
|
-
}
|
|
10048
9588
|
updateSyncStatus(options) {
|
|
10049
9589
|
const updatedStatus = new SyncStatus({
|
|
10050
9590
|
connected: options.connected ?? this.syncStatus.connected,
|
|
@@ -11583,14 +11123,12 @@ class SqliteBucketStorage extends BaseObserver {
|
|
|
11583
11123
|
db;
|
|
11584
11124
|
logger;
|
|
11585
11125
|
tableNames;
|
|
11586
|
-
_hasCompletedSync;
|
|
11587
11126
|
updateListener;
|
|
11588
11127
|
_clientId;
|
|
11589
11128
|
constructor(db, logger = Logger.get('SqliteBucketStorage')) {
|
|
11590
11129
|
super();
|
|
11591
11130
|
this.db = db;
|
|
11592
11131
|
this.logger = logger;
|
|
11593
|
-
this._hasCompletedSync = false;
|
|
11594
11132
|
this.tableNames = new Set();
|
|
11595
11133
|
this.updateListener = db.registerListener({
|
|
11596
11134
|
tablesUpdated: (update) => {
|
|
@@ -11602,7 +11140,6 @@ class SqliteBucketStorage extends BaseObserver {
|
|
|
11602
11140
|
});
|
|
11603
11141
|
}
|
|
11604
11142
|
async init() {
|
|
11605
|
-
this._hasCompletedSync = false;
|
|
11606
11143
|
const existingTableRows = await this.db.getAll(`SELECT name FROM sqlite_master WHERE type='table' AND name GLOB 'ps_data_*'`);
|
|
11607
11144
|
for (const row of existingTableRows ?? []) {
|
|
11608
11145
|
this.tableNames.add(row.name);
|
|
@@ -11624,156 +11161,6 @@ class SqliteBucketStorage extends BaseObserver {
|
|
|
11624
11161
|
getMaxOpId() {
|
|
11625
11162
|
return MAX_OP_ID;
|
|
11626
11163
|
}
|
|
11627
|
-
/**
|
|
11628
|
-
* Reset any caches.
|
|
11629
|
-
*/
|
|
11630
|
-
startSession() { }
|
|
11631
|
-
async getBucketStates() {
|
|
11632
|
-
const result = await this.db.getAll("SELECT name as bucket, cast(last_op as TEXT) as op_id FROM ps_buckets WHERE pending_delete = 0 AND name != '$local'");
|
|
11633
|
-
return result;
|
|
11634
|
-
}
|
|
11635
|
-
async getBucketOperationProgress() {
|
|
11636
|
-
const rows = await this.db.getAll('SELECT name, count_at_last, count_since_last FROM ps_buckets');
|
|
11637
|
-
return Object.fromEntries(rows.map((r) => [r.name, { atLast: r.count_at_last, sinceLast: r.count_since_last }]));
|
|
11638
|
-
}
|
|
11639
|
-
async saveSyncData(batch, fixedKeyFormat = false) {
|
|
11640
|
-
await this.writeTransaction(async (tx) => {
|
|
11641
|
-
for (const b of batch.buckets) {
|
|
11642
|
-
await tx.execute('INSERT INTO powersync_operations(op, data) VALUES(?, ?)', [
|
|
11643
|
-
'save',
|
|
11644
|
-
JSON.stringify({ buckets: [b.toJSON(fixedKeyFormat)] })
|
|
11645
|
-
]);
|
|
11646
|
-
this.logger.debug(`Saved batch of data for bucket: ${b.bucket}, operations: ${b.data.length}`);
|
|
11647
|
-
}
|
|
11648
|
-
});
|
|
11649
|
-
}
|
|
11650
|
-
async removeBuckets(buckets) {
|
|
11651
|
-
for (const bucket of buckets) {
|
|
11652
|
-
await this.deleteBucket(bucket);
|
|
11653
|
-
}
|
|
11654
|
-
}
|
|
11655
|
-
/**
|
|
11656
|
-
* Mark a bucket for deletion.
|
|
11657
|
-
*/
|
|
11658
|
-
async deleteBucket(bucket) {
|
|
11659
|
-
await this.writeTransaction(async (tx) => {
|
|
11660
|
-
await tx.execute('INSERT INTO powersync_operations(op, data) VALUES(?, ?)', ['delete_bucket', bucket]);
|
|
11661
|
-
});
|
|
11662
|
-
this.logger.debug(`Done deleting bucket ${bucket}`);
|
|
11663
|
-
}
|
|
11664
|
-
async hasCompletedSync() {
|
|
11665
|
-
if (this._hasCompletedSync) {
|
|
11666
|
-
return true;
|
|
11667
|
-
}
|
|
11668
|
-
const r = await this.db.get(`SELECT powersync_last_synced_at() as synced_at`);
|
|
11669
|
-
const completed = r.synced_at != null;
|
|
11670
|
-
if (completed) {
|
|
11671
|
-
this._hasCompletedSync = true;
|
|
11672
|
-
}
|
|
11673
|
-
return completed;
|
|
11674
|
-
}
|
|
11675
|
-
async syncLocalDatabase(checkpoint, priority) {
|
|
11676
|
-
const r = await this.validateChecksums(checkpoint, priority);
|
|
11677
|
-
if (!r.checkpointValid) {
|
|
11678
|
-
this.logger.error('Checksums failed for', r.checkpointFailures);
|
|
11679
|
-
for (const b of r.checkpointFailures ?? []) {
|
|
11680
|
-
await this.deleteBucket(b);
|
|
11681
|
-
}
|
|
11682
|
-
return { ready: false, checkpointValid: false, checkpointFailures: r.checkpointFailures };
|
|
11683
|
-
}
|
|
11684
|
-
if (priority == null) {
|
|
11685
|
-
this.logger.debug(`Validated checksums checkpoint ${checkpoint.last_op_id}`);
|
|
11686
|
-
}
|
|
11687
|
-
else {
|
|
11688
|
-
this.logger.debug(`Validated checksums for partial checkpoint ${checkpoint.last_op_id}, priority ${priority}`);
|
|
11689
|
-
}
|
|
11690
|
-
let buckets = checkpoint.buckets;
|
|
11691
|
-
if (priority !== undefined) {
|
|
11692
|
-
buckets = buckets.filter((b) => hasMatchingPriority(priority, b));
|
|
11693
|
-
}
|
|
11694
|
-
const bucketNames = buckets.map((b) => b.bucket);
|
|
11695
|
-
await this.writeTransaction(async (tx) => {
|
|
11696
|
-
await tx.execute(`UPDATE ps_buckets SET last_op = ? WHERE name IN (SELECT json_each.value FROM json_each(?))`, [
|
|
11697
|
-
checkpoint.last_op_id,
|
|
11698
|
-
JSON.stringify(bucketNames)
|
|
11699
|
-
]);
|
|
11700
|
-
if (priority == null && checkpoint.write_checkpoint) {
|
|
11701
|
-
await tx.execute("UPDATE ps_buckets SET last_op = ? WHERE name = '$local'", [checkpoint.write_checkpoint]);
|
|
11702
|
-
}
|
|
11703
|
-
});
|
|
11704
|
-
const valid = await this.updateObjectsFromBuckets(checkpoint, priority);
|
|
11705
|
-
if (!valid) {
|
|
11706
|
-
return { ready: false, checkpointValid: true };
|
|
11707
|
-
}
|
|
11708
|
-
return {
|
|
11709
|
-
ready: true,
|
|
11710
|
-
checkpointValid: true
|
|
11711
|
-
};
|
|
11712
|
-
}
|
|
11713
|
-
/**
|
|
11714
|
-
* Atomically update the local state to the current checkpoint.
|
|
11715
|
-
*
|
|
11716
|
-
* This includes creating new tables, dropping old tables, and copying data over from the oplog.
|
|
11717
|
-
*/
|
|
11718
|
-
async updateObjectsFromBuckets(checkpoint, priority) {
|
|
11719
|
-
let arg = '';
|
|
11720
|
-
if (priority !== undefined) {
|
|
11721
|
-
const affectedBuckets = [];
|
|
11722
|
-
for (const desc of checkpoint.buckets) {
|
|
11723
|
-
if (hasMatchingPriority(priority, desc)) {
|
|
11724
|
-
affectedBuckets.push(desc.bucket);
|
|
11725
|
-
}
|
|
11726
|
-
}
|
|
11727
|
-
arg = JSON.stringify({ priority, buckets: affectedBuckets });
|
|
11728
|
-
}
|
|
11729
|
-
return this.writeTransaction(async (tx) => {
|
|
11730
|
-
const { insertId: result } = await tx.execute('INSERT INTO powersync_operations(op, data) VALUES(?, ?)', [
|
|
11731
|
-
'sync_local',
|
|
11732
|
-
arg
|
|
11733
|
-
]);
|
|
11734
|
-
if (result == 1) {
|
|
11735
|
-
if (priority == null) {
|
|
11736
|
-
const bucketToCount = Object.fromEntries(checkpoint.buckets.map((b) => [b.bucket, b.count]));
|
|
11737
|
-
// The two parameters could be replaced with one, but: https://github.com/powersync-ja/better-sqlite3/pull/6
|
|
11738
|
-
const jsonBucketCount = JSON.stringify(bucketToCount);
|
|
11739
|
-
await tx.execute("UPDATE ps_buckets SET count_since_last = 0, count_at_last = ?->name WHERE name != '$local' AND ?->name IS NOT NULL", [jsonBucketCount, jsonBucketCount]);
|
|
11740
|
-
}
|
|
11741
|
-
return true;
|
|
11742
|
-
}
|
|
11743
|
-
else {
|
|
11744
|
-
return false;
|
|
11745
|
-
}
|
|
11746
|
-
});
|
|
11747
|
-
}
|
|
11748
|
-
async validateChecksums(checkpoint, priority) {
|
|
11749
|
-
if (priority !== undefined) {
|
|
11750
|
-
// Only validate the buckets within the priority we care about
|
|
11751
|
-
const newBuckets = checkpoint.buckets.filter((cs) => hasMatchingPriority(priority, cs));
|
|
11752
|
-
checkpoint = { ...checkpoint, buckets: newBuckets };
|
|
11753
|
-
}
|
|
11754
|
-
const rs = await this.db.execute('SELECT powersync_validate_checkpoint(?) as result', [
|
|
11755
|
-
JSON.stringify({ ...checkpoint })
|
|
11756
|
-
]);
|
|
11757
|
-
const resultItem = rs.rows?.item(0);
|
|
11758
|
-
if (!resultItem) {
|
|
11759
|
-
return {
|
|
11760
|
-
checkpointValid: false,
|
|
11761
|
-
ready: false,
|
|
11762
|
-
checkpointFailures: []
|
|
11763
|
-
};
|
|
11764
|
-
}
|
|
11765
|
-
const result = JSON.parse(resultItem['result']);
|
|
11766
|
-
if (result['valid']) {
|
|
11767
|
-
return { ready: true, checkpointValid: true };
|
|
11768
|
-
}
|
|
11769
|
-
else {
|
|
11770
|
-
return {
|
|
11771
|
-
checkpointValid: false,
|
|
11772
|
-
ready: false,
|
|
11773
|
-
checkpointFailures: result['failed_buckets']
|
|
11774
|
-
};
|
|
11775
|
-
}
|
|
11776
|
-
}
|
|
11777
11164
|
async updateLocalTarget(cb) {
|
|
11778
11165
|
const rs1 = await this.db.getAll("SELECT target_op FROM ps_buckets WHERE name = '$local' AND target_op = CAST(? as INTEGER)", [MAX_OP_ID]);
|
|
11779
11166
|
if (!rs1.length) {
|
|
@@ -11864,12 +11251,6 @@ class SqliteBucketStorage extends BaseObserver {
|
|
|
11864
11251
|
async writeTransaction(callback, options) {
|
|
11865
11252
|
return this.db.writeTransaction(callback, options);
|
|
11866
11253
|
}
|
|
11867
|
-
/**
|
|
11868
|
-
* Set a target checkpoint.
|
|
11869
|
-
*/
|
|
11870
|
-
async setTargetCheckpoint(checkpoint) {
|
|
11871
|
-
// No-op for now
|
|
11872
|
-
}
|
|
11873
11254
|
async control(op, payload) {
|
|
11874
11255
|
return await this.writeTransaction(async (tx) => {
|
|
11875
11256
|
const [[raw]] = await tx.executeRaw('SELECT powersync_control(?, ?)', [op, payload]);
|
|
@@ -11893,20 +11274,6 @@ class SqliteBucketStorage extends BaseObserver {
|
|
|
11893
11274
|
}
|
|
11894
11275
|
static _subkeyMigrationKey = 'powersync_js_migrated_subkeys';
|
|
11895
11276
|
}
|
|
11896
|
-
function hasMatchingPriority(priority, bucket) {
|
|
11897
|
-
return bucket.priority != null && bucket.priority <= priority;
|
|
11898
|
-
}
|
|
11899
|
-
|
|
11900
|
-
// TODO JSON
|
|
11901
|
-
class SyncDataBatch {
|
|
11902
|
-
buckets;
|
|
11903
|
-
static fromJSON(json) {
|
|
11904
|
-
return new SyncDataBatch(json.buckets.map((bucket) => SyncDataBucket.fromRow(bucket)));
|
|
11905
|
-
}
|
|
11906
|
-
constructor(buckets) {
|
|
11907
|
-
this.buckets = buckets;
|
|
11908
|
-
}
|
|
11909
|
-
}
|
|
11910
11277
|
|
|
11911
11278
|
/**
|
|
11912
11279
|
* Thrown when an underlying database connection is closed.
|
|
@@ -12217,13 +11584,9 @@ exports.MAX_OP_ID = MAX_OP_ID;
|
|
|
12217
11584
|
exports.MEMORY_TRIGGER_CLAIM_MANAGER = MEMORY_TRIGGER_CLAIM_MANAGER;
|
|
12218
11585
|
exports.Mutex = Mutex;
|
|
12219
11586
|
exports.OnChangeQueryProcessor = OnChangeQueryProcessor;
|
|
12220
|
-
exports.OpType = OpType;
|
|
12221
|
-
exports.OplogEntry = OplogEntry;
|
|
12222
11587
|
exports.Schema = Schema;
|
|
12223
11588
|
exports.Semaphore = Semaphore;
|
|
12224
11589
|
exports.SqliteBucketStorage = SqliteBucketStorage;
|
|
12225
|
-
exports.SyncDataBatch = SyncDataBatch;
|
|
12226
|
-
exports.SyncDataBucket = SyncDataBucket;
|
|
12227
11590
|
exports.SyncProgress = SyncProgress;
|
|
12228
11591
|
exports.SyncStatus = SyncStatus;
|
|
12229
11592
|
exports.SyncingService = SyncingService;
|
|
@@ -12238,18 +11601,10 @@ exports.createBaseLogger = createBaseLogger;
|
|
|
12238
11601
|
exports.createLogger = createLogger;
|
|
12239
11602
|
exports.extractTableUpdates = extractTableUpdates;
|
|
12240
11603
|
exports.isBatchedUpdateNotification = isBatchedUpdateNotification;
|
|
12241
|
-
exports.isContinueCheckpointRequest = isContinueCheckpointRequest;
|
|
12242
11604
|
exports.isDBAdapter = isDBAdapter;
|
|
12243
11605
|
exports.isPowerSyncDatabaseOptionsWithSettings = isPowerSyncDatabaseOptionsWithSettings;
|
|
12244
11606
|
exports.isSQLOpenFactory = isSQLOpenFactory;
|
|
12245
11607
|
exports.isSQLOpenOptions = isSQLOpenOptions;
|
|
12246
|
-
exports.isStreamingKeepalive = isStreamingKeepalive;
|
|
12247
|
-
exports.isStreamingSyncCheckpoint = isStreamingSyncCheckpoint;
|
|
12248
|
-
exports.isStreamingSyncCheckpointComplete = isStreamingSyncCheckpointComplete;
|
|
12249
|
-
exports.isStreamingSyncCheckpointDiff = isStreamingSyncCheckpointDiff;
|
|
12250
|
-
exports.isStreamingSyncCheckpointPartiallyComplete = isStreamingSyncCheckpointPartiallyComplete;
|
|
12251
|
-
exports.isStreamingSyncData = isStreamingSyncData;
|
|
12252
|
-
exports.isSyncNewCheckpointRequest = isSyncNewCheckpointRequest;
|
|
12253
11608
|
exports.parseQuery = parseQuery;
|
|
12254
11609
|
exports.runOnSchemaChange = runOnSchemaChange;
|
|
12255
11610
|
exports.sanitizeSQL = sanitizeSQL;
|