Skip to content

Commit 88006ec

Browse files
committed
Revert SyncDataBucket changes.
1 parent e372cf6 commit 88006ec

File tree

2 files changed

+50
-39
lines changed

2 files changed

+50
-39
lines changed

PowerSync/PowerSync.Common/Client/Sync/Bucket/SyncDataBucket.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,31 @@ public class SyncDataBucketJSON
99
[JsonProperty("bucket")]
1010
public string Bucket { get; set; } = null!;
1111

12-
// [JsonProperty("has_more")]
13-
// public bool? HasMore { get; set; }
12+
[JsonProperty("has_more")]
13+
public bool? HasMore { get; set; }
1414

15-
// [JsonProperty("after")]
16-
// public string? After { get; set; }
15+
[JsonProperty("after")]
16+
public string? After { get; set; }
1717

18-
// [JsonProperty("next_after")]
19-
// public string? NextAfter { get; set; }
18+
[JsonProperty("next_after")]
19+
public string? NextAfter { get; set; }
2020

2121
[JsonProperty("data")]
2222
public List<object> Data { get; set; } = [];
2323
}
2424

2525
public class SyncDataBucket(
2626
string bucket,
27-
OplogEntry[] data
28-
)
27+
OplogEntry[] data,
28+
bool hasMore,
29+
string? after = null,
30+
string? nextAfter = null)
2931
{
3032
public string Bucket { get; private set; } = bucket;
3133
public OplogEntry[] Data { get; private set; } = data;
34+
public bool HasMore { get; private set; } = hasMore;
35+
public string? After { get; private set; } = after;
36+
public string? NextAfter { get; private set; } = nextAfter;
3237

3338
public static SyncDataBucket FromRow(SyncDataBucketJSON row)
3439
{
@@ -41,7 +46,10 @@ public static SyncDataBucket FromRow(SyncDataBucketJSON row)
4146

4247
return new SyncDataBucket(
4348
row.Bucket,
44-
dataEntries
49+
dataEntries,
50+
row.HasMore ?? false,
51+
row.After,
52+
row.NextAfter
4553
);
4654
}
4755

@@ -55,6 +63,9 @@ public string ToJSON()
5563
var jsonObject = new SyncDataBucketJSON
5664
{
5765
Bucket = Bucket,
66+
HasMore = HasMore,
67+
After = After,
68+
NextAfter = NextAfter,
5869
Data = dataObjects
5970
};
6071

Tests/PowerSync/PowerSync.Common.Tests/Client/Sync/BucketStorageTests.cs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public async Task BasicSetup()
130130
var initialBucketStates = await bucketStorage.GetBucketStates();
131131
Assert.Empty(initialBucketStates);
132132

133-
await bucketStorage.SaveSyncData(new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])]));
133+
await bucketStorage.SaveSyncData(new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)]));
134134

135135
var bucketStates = await bucketStorage.GetBucketStates();
136136

@@ -154,7 +154,7 @@ public async Task ShouldGetObjectFromMultipleBuckets()
154154
{
155155
await bucketStorage.SaveSyncData(
156156
new SyncDataBatch(
157-
[new SyncDataBucket("bucket1", [TestData.putAsset1_3]), new SyncDataBucket("bucket2", [TestData.putAsset1_3])])
157+
[new SyncDataBucket("bucket1", [TestData.putAsset1_3], false), new SyncDataBucket("bucket2", [TestData.putAsset1_3], false)])
158158
);
159159

160160
await SyncLocalChecked(new Checkpoint
@@ -176,7 +176,7 @@ public async Task ShouldPrioritizeLaterUpdates()
176176

177177
await bucketStorage.SaveSyncData(
178178
new SyncDataBatch(
179-
[new SyncDataBucket("bucket1", [TestData.putAsset1_3]), new SyncDataBucket("bucket2", [TestData.putAsset1_1])])
179+
[new SyncDataBucket("bucket1", [TestData.putAsset1_3], false), new SyncDataBucket("bucket2", [TestData.putAsset1_1], false)])
180180
);
181181

182182
await SyncLocalChecked(new Checkpoint
@@ -193,7 +193,7 @@ public async Task ShouldIgnoreRemoveFromOneBucket()
193193
{
194194
// When we have 1 PUT and 1 REMOVE, the object must be kept.);
195195
await bucketStorage.SaveSyncData(
196-
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_3]), new SyncDataBucket("bucket2", [TestData.putAsset1_3, TestData.removeAsset1_4])])
196+
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_3], false), new SyncDataBucket("bucket2", [TestData.putAsset1_3, TestData.removeAsset1_4], false)])
197197
);
198198

199199
await SyncLocalChecked(new Checkpoint
@@ -210,7 +210,7 @@ public async Task ShouldRemoveWhenRemovedFromAllBuckets()
210210
{
211211
// When we only have REMOVE left for an object, it must be deleted.
212212
await bucketStorage.SaveSyncData(
213-
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_3, TestData.removeAsset1_5]), new SyncDataBucket("bucket2", [TestData.putAsset1_3, TestData.removeAsset1_4])])
213+
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_3, TestData.removeAsset1_5], false), new SyncDataBucket("bucket2", [TestData.putAsset1_3, TestData.removeAsset1_4], false)])
214214
);
215215

216216
await SyncLocalChecked(new Checkpoint
@@ -250,7 +250,7 @@ public async Task ShouldUseSubkeys()
250250
});
251251

252252
await bucketStorage.SaveSyncData(
253-
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset1_3, put4])])
253+
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset1_3, put4], false)])
254254
);
255255

256256
await SyncLocalChecked(new Checkpoint
@@ -262,7 +262,7 @@ await SyncLocalChecked(new Checkpoint
262262
var result = await db.GetAll<AssetResult>("SELECT id, description, make FROM assets WHERE id = 'O1'");
263263
Assert.Equal(new AssetResult("O1", "B", null), result[0]);
264264

265-
await bucketStorage.SaveSyncData(new SyncDataBatch([new SyncDataBucket("bucket1", [remove5])]));
265+
await bucketStorage.SaveSyncData(new SyncDataBatch([new SyncDataBucket("bucket1", [remove5], false)]));
266266

267267
await SyncLocalChecked(new Checkpoint
268268
{
@@ -278,7 +278,7 @@ public async Task ShouldFailChecksumValidation()
278278
{
279279
// Simple checksum validation
280280
await bucketStorage.SaveSyncData(
281-
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])])
281+
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)])
282282
);
283283

284284
var result = await bucketStorage.SyncLocalDatabase(new Checkpoint
@@ -304,7 +304,7 @@ public async Task ShouldDeleteBuckets()
304304
{
305305
await bucketStorage.SaveSyncData(
306306
new SyncDataBatch(
307-
[new SyncDataBucket("bucket1", [TestData.putAsset1_3]), new SyncDataBucket("bucket2", [TestData.putAsset1_3])])
307+
[new SyncDataBucket("bucket1", [TestData.putAsset1_3], false), new SyncDataBucket("bucket2", [TestData.putAsset1_3], false)])
308308
);
309309

310310
await bucketStorage.RemoveBuckets(["bucket2"]);
@@ -335,23 +335,23 @@ public async Task ShouldDeleteAndRecreateBuckets()
335335
{
336336
// Save some data
337337
await bucketStorage.SaveSyncData(
338-
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1])])
338+
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1], false)])
339339
);
340340

341341
// Delete the bucket
342342
await bucketStorage.RemoveBuckets(["bucket1"]);
343343

344344
// Save some data again
345345
await bucketStorage.SaveSyncData(
346-
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset1_3])])
346+
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset1_3], false)])
347347
);
348348

349349
// Delete again
350350
await bucketStorage.RemoveBuckets(["bucket1"]);
351351

352352
// Final save of data
353353
await bucketStorage.SaveSyncData(
354-
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset1_3])])
354+
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset1_3], false)])
355355
);
356356

357357
// Check that the data is there
@@ -388,12 +388,12 @@ await bucketStorage.SaveSyncData(
388388
Op = new OpType(OpTypeEnum.MOVE).ToJSON(),
389389
Checksum = 1
390390
})
391-
])
391+
], false)
392392
])
393393
);
394394

395395
await bucketStorage.SaveSyncData(
396-
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_3])])
396+
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_3], false)])
397397
);
398398

399399
await SyncLocalChecked(new Checkpoint
@@ -412,7 +412,7 @@ public async Task ShouldHandleClear()
412412
await bucketStorage.SaveSyncData(
413413
new SyncDataBatch(
414414
[
415-
new SyncDataBucket("bucket1", [TestData.putAsset1_1])
415+
new SyncDataBucket("bucket1", [TestData.putAsset1_1], false)
416416
])
417417
);
418418

@@ -446,7 +446,7 @@ await bucketStorage.SaveSyncData(
446446
ObjectId = TestData.putAsset2_2.ObjectId,
447447
ObjectType = TestData.putAsset2_2.ObjectType
448448
})
449-
])
449+
], false)
450450
])
451451
);
452452

@@ -478,7 +478,7 @@ public async Task UpdateWithNewTypes()
478478

479479
await bucketStorage.SaveSyncData(
480480
new SyncDataBatch(
481-
[new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])])
481+
[new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)])
482482
);
483483

484484
await SyncLocalChecked(new Checkpoint
@@ -524,7 +524,7 @@ public async Task ShouldRemoveTypes()
524524
await bucketStorage.SaveSyncData(
525525
new SyncDataBatch(
526526
[
527-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])
527+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)
528528
])
529529
);
530530

@@ -578,7 +578,7 @@ public async Task ShouldCompact()
578578
await bucketStorage.SaveSyncData(
579579
new SyncDataBatch(
580580
[
581-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.removeAsset1_4])
581+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.removeAsset1_4], false)
582582
])
583583
);
584584

@@ -613,7 +613,7 @@ public async Task ShouldNotSyncLocalDbWithPendingCrud_ServerRemoved()
613613
await bucketStorage.SaveSyncData(
614614
new SyncDataBatch(
615615
[
616-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])
616+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)
617617
])
618618
);
619619

@@ -676,7 +676,7 @@ await SyncLocalChecked(new Checkpoint
676676
await bucketStorage.SaveSyncData(
677677
new SyncDataBatch(
678678
[
679-
new SyncDataBucket("bucket1", Array.Empty<OplogEntry>())
679+
new SyncDataBucket("bucket1", Array.Empty<OplogEntry>(), false)
680680
])
681681
);
682682

@@ -700,7 +700,7 @@ public async Task ShouldNotSyncLocalDbWithPendingCrud_WhenMoreCrudIsAdded_1()
700700
await bucketStorage.SaveSyncData(
701701
new SyncDataBatch(
702702
[
703-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])
703+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)
704704
])
705705
);
706706

@@ -743,7 +743,7 @@ await SyncLocalChecked(new Checkpoint
743743
await bucketStorage.SaveSyncData(
744744
new SyncDataBatch(
745745
[
746-
new SyncDataBucket("bucket1", Array.Empty<OplogEntry>())
746+
new SyncDataBucket("bucket1", Array.Empty<OplogEntry>(), false)
747747
])
748748
);
749749

@@ -769,7 +769,7 @@ public async Task ShouldNotSyncLocalDbWithPendingCrud_WhenMoreCrudIsAdded_2()
769769
await bucketStorage.SaveSyncData(
770770
new SyncDataBatch(
771771
[
772-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])
772+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)
773773
])
774774
);
775775

@@ -797,7 +797,7 @@ await SyncLocalChecked(new Checkpoint
797797
await bucketStorage.SaveSyncData(
798798
new SyncDataBatch(
799799
[
800-
new SyncDataBucket("bucket1", [])
800+
new SyncDataBucket("bucket1", [], false)
801801
])
802802
);
803803

@@ -826,7 +826,7 @@ public async Task ShouldNotSyncLocalDbWithPendingCrud_UpdateOnServer()
826826
await bucketStorage.SaveSyncData(
827827
new SyncDataBatch(
828828
[
829-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])
829+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)
830830
])
831831
);
832832

@@ -865,7 +865,7 @@ await bucketStorage.SaveSyncData(
865865
Checksum = 5,
866866
Data = new { description = "server updated" }
867867
})
868-
])
868+
], false)
869869
])
870870
);
871871

@@ -889,7 +889,7 @@ public async Task ShouldRevertAFailingInsert()
889889
await bucketStorage.SaveSyncData(
890890
new SyncDataBatch(
891891
[
892-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])
892+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)
893893
])
894894
);
895895

@@ -931,7 +931,7 @@ public async Task ShouldRevertAFailingDelete()
931931
await bucketStorage.SaveSyncData(
932932
new SyncDataBatch(
933933
[
934-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])
934+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)
935935
])
936936
);
937937

@@ -974,7 +974,7 @@ public async Task ShouldRevertAFailingUpdate()
974974
await bucketStorage.SaveSyncData(
975975
new SyncDataBatch(
976976
[
977-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])
977+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)
978978
])
979979
);
980980

0 commit comments

Comments
 (0)